Download, concatenate and minifiy the content of several links.

@param  array   $links
@param  Closure $minifier
@return string
776737
protected function packLinks(array $links, Closure $minifier)
	{
		$buffer = '';
		foreach($links as $link)
		{
			$originalLink = $link;

			// Get real link path
			if($this->isRemoteLink($link))
			{
				// Add current protocol to agnostic links
				if('//' === substr($link, 0, 2))
				{
					$protocol = (isset($_SERVER['HTTPS']) and ! empty($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== 'off') ? 'https:' : 'http:';
					$link = $protocol . $link;
				}
			}
			else
			{
				$link = realpath($this->public_dir . DIRECTORY_SEPARATOR . $link);
				if($link === false)
					continue;
			}

			// Fetch link content
			$content = ($this->fetch_command instanceof Closure) ? $this->fetch_command->__invoke($link) : file_get_contents($link);

			// Minify
			$buffer .= (preg_match($this->no_minification_regex, $originalLink)) ? $content : $minifier->__invoke($content);

			// Avoid JavaScript minification problems
			$buffer .= PHP_EOL;
		}

		return $buffer;
	}
113651
public function toString(\Closure $linkFormatterCallback = null)
    {

        $format = $this->getFormat();

        $linkFormatter = (null !== $linkFormatterCallback) ? $linkFormatterCallback : self::getDefaultLinkFormatter();
        $placeholderFormatter = self::getPlaceholderFormatter();

        foreach ($this->getArgs() as $arg) {
            switch ($arg->getType()) {
                case ArgTypes::ARG_TYPE_HYPERLINK:
                    $format = $linkFormatter($arg, $format);
                    break;
                case ArgTypes::ARG_TYPE_BYTES:
                case ArgTypes::ARG_TYPE_DISTANCE:
                case ArgTypes::ARG_TYPE_DURATION:
                case ArgTypes::ARG_TYPE_INT_LITERAL:
                case ArgTypes::ARG_TYPE_PERCENTAGE:
                case ArgTypes::ARG_TYPE_SNAPSHOT_RECT:
                case ArgTypes::ARG_TYPE_STRING_LITERAL:
                case ArgTypes::ARG_TYPE_URL:
                case ArgTypes::ARG_TYPE_VERBATIM_STRING:
                    $format = $placeholderFormatter($arg, $format);
                    break;
                default:
                    throw new ArgException(sprintf('Unknown argument type: "%s"!', $arg->getType()));
            }
        }

        return $format;
    }
1011446
public function buildSimpleLink($output, Link $link)
    {
        $name = $link->getName();

        $output->$name = $link->getHref();

        return $output;
    }
1244027
public function concatenate(array $bindings = [])
    {
        // Filter out empty query segments.
        $bindings = array_filter($bindings, function ($value) {
            return (string) $value !== '';
        });

        return implode('', $bindings);
    }
383577
protected function minifiers(MinifyContext $context, $options = [])
    {
        foreach ($this->minifiers as $minifier) {
            $minifier = new $minifier();

            $provides = $minifier->provides();
            if ($this->runAll($options) || $this->isOptionSet($provides, $options)) {
                $context = $minifier->process($context);
                $context->addMinificationStep($context->getContents(), $this->getClassName($minifier).'|'.$minifier->provides());
            }
        }

        return $context;
    }
1228503
public function compress($type, $files, $file) 
	{
		// files have been updated so update the minified file
		if($this->isUpdated($files))
		{
			$content = $this->getFileContents($files);
			switch($type){
				case 'css':
					$content = $this->minifyCSS($content);
				break;
				case 'js':
					$content = $this->minifyJS($content);
				break;
			}
			$this->saveFile($file, $content);
		}
		return str_replace($this->scriptPath,$this->coreUrl,$file);	
	}
673179
protected function appendIterator(\Closure $callback = null)
    {
        $iterator = new \AppendIterator();

        $paths = (array) parent::getArrayCopy();

        $clousre = function ($path) use ($callback, $iterator) {
            $iterator->append($callback($path));
        };

        foreach ($this as $path) {
            if ($this->isSubdir($path)) {
                continue;
            }

            $clousre($path);
        }

        return $iterator;
    }
166829
protected function exportLinks($result)
    {
        $extraLinkList = $this->doc->createElement('ul');
        $labelFormat = LocalizationUtility::translate('download-label-format-simple', 'Pazpar2');
        if (count($result['location']) > 1) {
            $labelFormat = LocalizationUtility::translate('download-label-format-all', 'Pazpar2');
        }

        if ($this->conf['showKVKLink'] == 1) {
            $this->appendInfoToContainer($this->KVKItem($result), $extraLinkList);
        }
        $this->appendExportItemsTo($result['location'], $labelFormat, $extraLinkList);
        // Separate submenus for individual locations not implemented in the PHP version.

        $exportLinks = null;
        if ($extraLinkList->hasChildNodes()) {
            $exportLinks = $this->doc->createElement('div');
            $exportLinks->setAttribute('class', 'pz2-extraLinks');
            $exportLinksLabel = $this->doc->createElement('span');
            $exportLinks->appendChild($exportLinksLabel);
            $exportLinksLabel->setAttribute('class', 'pz2-extraLinksLabel');
            $exportLinksLabel->appendChild($this->doc->createTextNode(LocalizationUtility::translate('mehr Links', 'Pazpar2')));
            $exportLinks->appendChild($extraLinkList);
        }

        return $exportLinks;
    }
868245
public function generateLinksApplications(array $applications)
    {
        $links = [];

        foreach ($applications as $application) {
            if ($this->codeApplication === $application->getCode()) {
                continue;
            }

            $links[] = [
                'href' => $application->getHref(),
                'title' => $application->getTitle(),
            ];
        }

        return $links;
    }
1073693
public static function Links($Mixed) {
      if (!is_string($Mixed))
         return self::To($Mixed, 'Links');
      else {
         $Regex = "`(?:(</?)([!a-z]+))|(/?\s*>)|((?:https?|ftp)://[\@a-z0-9\x21\x23-\x27\x2a-\x2e\x3a\x3b\/;\x3f-\x7a\x7e\x3d]+)`i";

//         $Parts = preg_split($Regex, $Mixed, null, PREG_SPLIT_DELIM_CAPTURE);
//         echo '<pre>', print_r($Parts, TRUE), '</pre>';

         self::LinksCallback(NULL);

         $Mixed = preg_replace_callback(
            $Regex,
         array('Gdn_Format', 'LinksCallback'),
         $Mixed);

         return $Mixed;
      }
   }
1125404
protected function createBrowsersFor(Closure $callback)
    {
        if (count(static::$browsers) === 0) {
            static::$browsers = collect([$this->newBrowser($this->createWebDriver())]);
        }

        $additional = $this->browsersNeededFor($callback) - 1;

        for ($i = 0; $i < $additional; $i++) {
            static::$browsers->push($this->newBrowser($this->createWebDriver()));
        }

        return static::$browsers;
    }
1373512
public static function compress($js)
    {
        $js = (string) $js;
        try {
            $js_minifier = new static($js);
            $minified_js = $js_minifier->min();
            return $minified_js;
        } catch (\Exception $exception) {
            return $js;
        }
    }
1328496
private function renderView($links)
	{
		$defaults = $this->defaults;

		return View::make($this->view, compact('links', 'defaults'))->render();
	}
1343267
public static function implode(Array $array, $glue, Closure $closure) {
    return implode($glue, array_map($closure, (array) $array, array_keys($array)));
  }
819277
public function serializeClosure(\Closure $closure)
    {
        if ($this->isSingle()) {
            return SerializeHelper::component()->serializeClosure($closure);
        }

        return null;
    }
1249136
public function header(Closure $closure = null)
    {
        if (!$closure) {
            return $this->header;
        }

        $this->header = $closure;

        return $this;
    }
620657
private function copy(array $sources, $dest, $minify)
    {
        // create destination path if not exists

        $ext = pathinfo($dest, PATHINFO_EXTENSION);
        $dir = !empty($ext) ? dirname($dest) : $dest;
        if (!file_exists($dir)) {
            if (!make_dir($dir, 0775)) {
                throw new RuntimeException('Unable to create directory ' . $dir); // @codeCoverageIgnore
            }
        }

        // list all source files into a flat array

        $files = [];
        foreach ($sources as $source) {
            if (is_dir($source)) {
                if ($ext == 'js') {
                    $filter = ['js'];
                }
                else if ($ext == 'css') {
                    $filter = ['css', 'less', 'scss'];
                }
                else {
                    $filter = null;
                }
                list_files($files, $source, $filter);
            }
            else {
                $files[] = $source;
            }
        }

        // copy all files to the destination

        if (file_exists($dest) && !is_dir($dest)) {
            unlink($dest);
        } // @codeCoverageIgnore

        foreach ($files as $file) {
            // get content
            $content = file_get_contents($file);

            // compile
            $srcExt = pathinfo($file, PATHINFO_EXTENSION);
            switch ($srcExt) {
                case 'less':
//                    $content = (new LessCompiler)->compile($content);
                    $content = (new LessCompiler)->parse($content)->getCss();
                    break;
                case 'scss':
                    $content = (new SCSSCompiler)->compile($content);
                    break;
            }

            // minimize
            if ($minify) {
                switch ($srcExt) {
                    case 'js':
                        $content = JSMin::minify($content);
                        break;
                    case 'css':
                    case 'less':
                    case 'scss':
                        $content = CssMin::minify($content);
                        break;
                }
            }

            // save content
            if (is_dir($dest)) {
                $success = file_put_contents($dest . DIRECTORY_SEPARATOR . basename($file), $content, LOCK_EX);
                //@chmod($dest . DIRECTORY_SEPARATOR . basename($file), 0664);
            }
            else {
                // concatenate the files to a single file
                if (file_exists($dest)) {
                    $success = file_put_contents($dest, PHP_EOL . $content, FILE_APPEND | LOCK_EX);
                }
                else {
                    $success = file_put_contents($dest, $content, LOCK_EX);
                    //@chmod($dest, 0664);
                }
            }
            if ($success === false) {
                throw new RuntimeException(sprintf('Asset Manager was not able to copy "%s" to "%s"', $file, $dest)); // @codeCoverageIgnore
            }
        }
    }