Run the asset through UglifyJs

@see Assetic\Filter\FilterInterface::filterDump()
514494
public function filterDump(AssetInterface $asset)
    {
        $pb = $this->createProcessBuilder($this->nodeBin
            ? array($this->nodeBin, $this->uglifyjsBin)
            : array($this->uglifyjsBin));

        if ($this->noCopyright) {
            $pb->add('--no-copyright');
        }

        if ($this->beautify) {
            $pb->add('--beautify');
        }

        if ($this->unsafe) {
            $pb->add('--unsafe');
        }

        if (false === $this->mangle) {
            $pb->add('--no-mangle');
        }

        // input and output files
        $input = tempnam(sys_get_temp_dir(), 'input');
        $output = tempnam(sys_get_temp_dir(), 'output');

        file_put_contents($input, $asset->getContent());
        $pb->add('-o')->add($output)->add($input);

        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);

        if (0 !== $code) {
            if (file_exists($output)) {
                unlink($output);
            }

            if (127 === $code) {
                throw new \RuntimeException('Path to node executable could not be resolved.');
            }

            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }

        if (!file_exists($output)) {
            throw new \RuntimeException('Error creating output file.');
        }

        $uglifiedJs = file_get_contents($output);
        unlink($output);

        $asset->setContent($uglifiedJs);
    }
219726
public function run()
	{
		$this->say('Updating ' . $this->getJConfig()->extension . " to " . $this->getJConfig()->version);

		// Reusing the header config here
		$exclude = explode(",", trim($this->getJConfig()->header->exclude));

		$path      = realpath($this->getJConfig()->source);
		$fileTypes = explode(",", trim($this->getJConfig()->header->files));

		$changedFiles = 0;

		foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)) as $filename)
		{
			if (substr($filename, 0, 1) == '.')
			{
				continue;
			}

			$file = new \SplFileInfo($filename);

			if (!in_array($file->getExtension(), $fileTypes))
			{
				continue;
			}

			// Skip directories in exclude list
			if (isset($exclude) && count($exclude))
			{
				$relative = str_replace(realpath($path), "", $file->getPath());

				// It is possible to have multiple exclude directories
				foreach ($exclude as $e)
				{
					if (stripos($relative, $e) !== false)
					{
						$this->say("Excluding " . $filename);
						continue 2;
					}
				}
			}

			// Load the file
			$fileContents = file_get_contents($file->getRealPath());

			if (preg_match('#__DEPLOY_VERSION__#', $fileContents))
			{
				$fileContents = preg_replace('#__DEPLOY_VERSION__#', $this->getJConfig()->version, $fileContents);

				$this->say('Updating file: ' . $file->getRealPath());

				file_put_contents($file->getRealPath(), $fileContents);

				$changedFiles++;
			}
		}

		$this->say('Updated ' . $changedFiles . ' files');

		return true;
	}
107927
private function applyFilters()
    {
        $availableOptions = ['name', 'method', 'uri', 'action', 'middleware'];
        foreach ($this->options() as $key => $option) {
            if (in_array($key, $availableOptions) && null != $option) {
                foreach ($this->routes as $index => $route) {
                    if (!str_contains(strtolower($route[$key]), strtolower($option)))
                        unset($this->routes[$index]);
                }
            }
        }
    }
1265185
private function doDump(AssetInterface $asset, OutputInterface $stdout)
    {
        $combinations = VarUtils::getCombinations(
            $asset->getVars(),
            $this->getContainer()->getParameter('assetic.variables')
        );

        foreach ($combinations as $combination) {
            $asset->setValues($combination);

            // resolve the target path
            $target = rtrim($this->basePath, '/').'/'.$asset->getTargetPath();
            $target = str_replace('_controller/', '', $target);
            $target = VarUtils::resolve($target, $asset->getVars(), $asset->getValues());

            if (!is_dir($dir = dirname($target))) {
                $stdout->writeln(sprintf(
                    '<comment>%s</comment> <info>[dir+]</info> %s',
                    date('H:i:s'),
                    $dir
                ));

                if (false === @mkdir($dir, 0777, true)) {
                    throw new \RuntimeException('Unable to create directory '.$dir);
                }
            }

            $stdout->writeln(sprintf(
                '<comment>%s</comment> <info>[file+]</info> %s',
                date('H:i:s'),
                $target
            ));

            if (OutputInterface::VERBOSITY_VERBOSE <= $stdout->getVerbosity()) {
                if ($asset instanceof AssetCollectionInterface) {
                    foreach ($asset as $leaf) {
                        $root = $leaf->getSourceRoot();
                        $path = $leaf->getSourcePath();
                        $stdout->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
                    }
                } else {
                    $root = $asset->getSourceRoot();
                    $path = $asset->getSourcePath();
                    $stdout->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
                }
            }

            if (false === @file_put_contents($target, $asset->dump())) {
                throw new \RuntimeException('Unable to write file '.$target);
            }
        }
    }
224563
public function filterDump(AssetInterface $asset)
    {
        $pb = $this->createProcessBuilder($this->nodeBin
            ? array($this->nodeBin, $this->cleanCssBin)
            : array($this->cleanCssBin));

        if ($this->keepLineBreaks) {
            $pb->add('--keep-line-breaks');
        }

        if ($this->compatibility) {
            $pb->add('--compatibility ' .$this->compatibility);
        }

        if ($this->debug) {
            $pb->add('--debug');
        }

        if ($this->rootPath) {
            $pb->add('--root ' .$this->rootPath);
        }

        if ($this->skipImport) {
            $pb->add('--skip-import');
        }

        if ($this->timeout) {
            $pb->add('--timeout ' .$this->timeout);
        }

        if ($this->roundingPrecision) {
            $pb->add('--rounding-precision ' .$this->roundingPrecision);
        }

        if ($this->removeSpecialComments) {
            $pb->add('--s0');
        }

        if ($this->onlyKeepFirstSpecialComment) {
            $pb->add('--s1');
        }

        if ($this->semanticMerging) {
            $pb->add('--semantic-merging');
        }

        if ($this->skipAdvanced) {
            $pb->add('--skip-advanced');
        }

        if ($this->skipAggresiveMerging) {
            $pb->add('--skip-aggressive-merging');
        }

        if ($this->skipImportFrom) {
            $pb->add('--skip-import-from ' .$this->skipImportFrom);
        }

        if ($this->mediaMerging) {
            $pb->add('--skip-media-merging');
        }

        if ($this->skipRebase) {
            $pb->add('--skip-rebase');
        }

        if ($this->skipRestructuring) {
            $pb->add('--skip-restructuring');
        }

        if ($this->skipShorthandCompacting) {
            $pb->add('--skip-shorthand-compacting');
        }

        if ($this->sourceMap) {
            $pb->add('--source-map');
        }

        if ($this->sourceMapInlineSources) {
            $pb->add('--source-map-inline-sources');
        }
        // input and output files
        $input = tempnam(sys_get_temp_dir(), 'input');

        file_put_contents($input, $asset->getContent());
        $pb->add($input);

        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);

        if (127 === $code) {
            throw new \RuntimeException('Path to node executable could not be resolved.');
        }

        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }

        $asset->setContent($proc->getOutput());
    }
210955
public function run()
	{

		list($name) = $this->resolveNameID();

		$this->htmlOptions['id'] = $this->id.'-'.($this->hasModel() ? get_class($this->model) : 'fileupload') . '-form';

		$this->options['url'] = $this->url;

		// if acceptFileTypes is not set as option, try getting it from models rules
		if (!isset($this->options['acceptFileTypes'])) {
			$fileTypes = $this->getFileValidatorProperty($this->model, $this->attribute, 'types');
			if (isset($fileTypes)) {
				$fileTypes = (preg_match(':jpg:', $fileTypes) && !preg_match(':jpe:', $fileTypes) ? preg_replace(
					':jpg:',
					'jpe?g',
					$fileTypes
				) : $fileTypes);
				$this->options['acceptFileTypes'] = 'js:/(\.)(' . preg_replace(':,:', '|', $fileTypes) . ')$/i';
			}
		}

		// if maxFileSize is not set as option, try getting it from models rules
		if (!isset($this->options['maxFileSize'])) {
			$fileSize = $this->getFileValidatorProperty($this->model, $this->attribute, 'maxSize');
			if (isset($fileSize)) {
				$this->options['maxFileSize'] = $fileSize;
			}
		}

		if ($this->multiple) {
			$this->htmlOptions["multiple"] = true;
		}

		$this->render($this->uploadView);
		$this->render($this->downloadView);
		$this->render($this->formView, array('name' => $name, 'htmlOptions' => $this->htmlOptions));

		if ($this->previewImages || $this->imageProcessing) {
			$this->render($this->previewImagesView);
		}

		$this->registerClientScript($this->htmlOptions['id']);
	}
1271854
public function apply()
	{
		foreach ($this->patches as $patch)
		{
			// Separate the input into lines
			$lines = self::splitLines($patch['udiff']);

			// Loop for each header
			while (self::findHeader($lines, $src, $dst))
			{
				$done = false;

				if ($patch['strip'] === null)
				{
					$src = $patch['root'] . preg_replace('#^([^/]*/)*#', '', $src);
					$dst = $patch['root'] . preg_replace('#^([^/]*/)*#', '', $dst);
				}
				else
				{
					$src = $patch['root'] . preg_replace('#^([^/]*/){' . (int) $patch['strip'] . '}#', '', $src);
					$dst = $patch['root'] . preg_replace('#^([^/]*/){' . (int) $patch['strip'] . '}#', '', $dst);
				}

				// Loop for each hunk of differences
				while (self::findHunk($lines, $src_line, $src_size, $dst_line, $dst_size))
				{
					$done = true;

					// Apply the hunk of differences
					$this->applyHunk($lines, $src, $dst, $src_line, $src_size, $dst_line, $dst_size);
				}

				// If no modifications were found, throw an exception
				if (!$done)
				{
					throw new \RuntimeException('Invalid Diff');
				}
			}
		}

		// Initialize the counter
		$done = 0;

		// Patch each destination file
		foreach ($this->destinations as $file => $content)
		{
			$content = implode("\n", $content);

			if (File::write($file, $content))
			{
				if (isset($this->sources[$file]))
				{
					$this->sources[$file] = $content;
				}

				$done++;
			}
		}

		// Remove each removed file
		foreach ($this->removals as $file)
		{
			if (File::delete($file))
			{
				if (isset($this->sources[$file]))
				{
					unset($this->sources[$file]);
				}

				$done++;
			}
		}

		// Clear the destinations cache
		$this->destinations = array();

		// Clear the removals
		$this->removals = array();

		// Clear the patches
		$this->patches = array();

		return $done;
	}
1244110
public function doFilter($file, $arguments, $cssOptions)
    {
        if (! $arguments['minify']) {
            return;
        }

        $content = file_get_contents($file);
        $compressor = new CSSmin();

        if (Utils::isSerialized($content, $content)) {
            $content['compiled'] = $compressor->run($content['compiled']);
            $content = serialize($content);
        } else {
            $content = $compressor->run($content);
        }

        file_put_contents($file, $content);
    }
1299681
function convert( $manager, $sourceMimeData, &$destinationMimeData, $filters = false )
    {
        $sourceMimeType = $sourceMimeData['name'];
        $destinationMimeType = $destinationMimeData['name'];
        if ( !isset( $this->InputMap[$sourceMimeType] ) )
        {
            eZDebug::writeError( "MIME-Type $sourceMimeType is not supported as input by GD converter", __METHOD__ );
            return false;
        }
        if ( !isset( $this->OutputMap[$destinationMimeType] ) )
        {
            eZDebug::writeError( "MIME-Type $destinationMimeType is not supported as output by GD converter", __METHOD__ );
            return false;
        }

        $inputFunction = $this->InputMap[$sourceMimeType];
        $outputFunction = $this->OutputMap[$destinationMimeType];
        $outputQualityParameter = $this->OutputQualityMap[$destinationMimeType];
        $inputFile = $sourceMimeData['url'];
        $outputFile = $destinationMimeData['url'];

        if ( !file_exists( $inputFile ) )
        {
            eZDebug::writeError( "Source image $inputFile does not exist, cannot convert", __METHOD__ );
            return false;
        }

        $currentImage = $inputFunction( $inputFile );

        $filterVariables = array( 'border-color' => array( 127, 127, 127 ),
                                  'border-size' => array( 0, 0 ) );

        if ( $filters !== false )
        {
            foreach ( $filters as $filterData )
            {
                $filterName = $filterData['name'];
                if ( isset( $this->FilterFunctionMap[$filterName] ) )
                {
                    $filterFunction = $this->FilterFunctionMap[$filterName];
                    $filteredImage = $this->$filterFunction( $currentImage, $filterData, $filterVariables, $sourceMimeData, $destinationMimeData );
                    if ( $filteredImage !== false )
                    {
                        if ( $filteredImage != $currentImage )
                        {
                            ImageDestroy( $currentImage );
                        }
                        $currentImage = $filteredImage;
                    }
                }
            }
        }

        $outputImage = $currentImage;

        if ( $outputImage )
        {
            $outputQuality = false;
            if ( $outputQualityParameter )
                $outputQuality = $manager->qualityValue( $destinationMimeType );
            if ( $outputQuality !== false )
            {
                $returnCode = $outputFunction( $outputImage, $outputFile, $outputQuality );
            }
            else
            {
                $returnCode = $outputFunction( $outputImage, $outputFile );
            }

            ImageDestroy( $outputImage );
        }
        else
            $returnCode = false;

        if ( $returnCode )
        {
            if ( !file_exists( $destinationMimeData['url'] ) )
            {
                eZDebug::writeError( "Unknown destination file: " . $destinationMimeData['url'], "eZImageGDHandler(" . $this->HandlerName . ")" );
                return false;
            }
            $this->changeFilePermissions( $destinationMimeData['url'] );
            return true;
        }
        else
        {
            eZDebug::writeWarning( "Failed converting $inputFile ($sourceMimeType) to $outputFile ($destinationMimeType)", __METHOD__ );
            return false;
        }
    }
257093
public function renderTableFooter()
	{
		$hasFilter = $this->filter !== null && $this->filterPosition === self::FILTER_POS_FOOTER;

		$hasFooter = $this->getHasFooter();
		if ($this->bulk !== null || $hasFilter || $hasFooter) {
			echo "<tfoot>\n";
			if ($hasFooter) {
				echo "<tr>\n";
				/** @var $column CDataColumn */
				foreach ($this->columns as $column) {
					$column->renderFooterCell();
				}
				echo "</tr>\n";
			}
			if ($hasFilter) {
				$this->renderFilter();
			}

			if ($this->bulk !== null) {
				$this->renderBulkActions();
			}
			echo "</tfoot>\n";
		}
	}
381393
public function run()
    {
        $params = $this->params;
        $params['content'] = ob_get_clean();
        // render under the existing context
        return $this->view->renderFile($this->viewFile, $params);
    }
346834
public function filterLoad(AssetInterface $asset)
    {
        if ('' != ($sourceRoot = $asset->getSourceRoot()) && '' != ($sourcePath = $asset->getSourcePath())) {
            $input = $sourceRoot . '/' . $sourcePath;
            $remove = false;
        } else {
            $input = tempnam(sys_get_temp_dir(), 'assetic_jshint');
            file_put_contents($input, $asset->getContent());
            $remove = true;
        }

        $pb = $this->createProcessBuilder(array($this->jsHintBinary));
        $pb->add($input);
        $proc = $pb->getProcess();
        $code = $proc->run();

        if (true === $remove) {
            unlink($input);
        }

        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
    }
1144396
protected function cacheJsAssetFiles()
    {
        if ($this->getOptions()->isProduction()) {
            // Retrieve asset file filters manager
            $oAssetFileFiltersManager = $this->getAssetFileFiltersManager();

            // Retrieve Js asset file filter if available
            $oJsFileFilter = $oAssetFileFiltersManager->has(\AssetsBundle\AssetFile\AssetFile::ASSET_JS) ? $oAssetFileFiltersManager->get(\AssetsBundle\AssetFile\AssetFile::ASSET_JS) : null;

            // Create tmp asset file
            $oTmpAssetFile = $this->createTmpAssetFile(\AssetsBundle\AssetFile\AssetFile::ASSET_JS);

            foreach ($this->getAssetFilesConfiguration()->getAssetFiles(\AssetsBundle\AssetFile\AssetFile::ASSET_JS) as $oAssetFile) {
                $sAssetFileContent = $oJsFileFilter ? $oJsFileFilter->filterAssetFile($oAssetFile) : $oAssetFile->getAssetFileContents();
                $oTmpAssetFile->setAssetFileContents($sAssetFileContent . PHP_EOL);
            }
            if($oTmpAssetFile->getAssetFileSize()){
                return array($this->getAssetFilesCacheManager()->cacheAssetFile($oTmpAssetFile));
            }
            return array();
        }

        // Retrieve asset files cache manager
        $oAssetFilesCacheManager = $this->getAssetFilesCacheManager();
        $aAssetFiles = array();
        foreach ($this->getAssetFilesConfiguration()->getAssetFiles(\AssetsBundle\AssetFile\AssetFile::ASSET_JS) as $oAssetFile) {
            // Cache asset file if not empty
            if($oAssetFile->getAssetFileSize()){
                $aAssetFiles[] = $oAssetFilesCacheManager->cacheAssetFile($oAssetFile);
            }
        }
        return $aAssetFiles;
    }
323602
public function run($hook, $args = null)
    {
        if (is_array($args)) {
            return $this->applyFiltersRefArray($hook, $args);
        }

        return $this->applyFilters($hook, $args);
    }
1370113
protected function dumpAssets($files, $targetFilename = null, $useRequireJs = false)
    {
        $content = '';
        foreach ($files as $file) {
            $content .= file_get_contents($file) . "\n";
        }
        if ($useRequireJs) {
            $content = "define('debugbar', ['jquery'], function($){\r\n" . $content . "\r\n return PhpDebugBar; \r\n});";
        }
        if ($targetFilename !== null) {
            file_put_contents($targetFilename, $content);
        } else {
            echo $content;
        }
    }
416177
public function run() {

		foreach ( $this->filters as $hook ) {
			add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
		}

		foreach ( $this->actions as $hook ) {
			add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
		}

	}
793896
public function doFilter($file, $arguments, $javaScriptOptions)
    {
        if (! $arguments['minify']) {
            return;
        }

        file_put_contents($file, Minifier::minify(file_get_contents($file)));
    }