Example #1
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->jpegtranBin));
     if ($this->optimize) {
         $pb->add('-optimize');
     }
     if ($this->copy) {
         $pb->add('-copy')->add($this->copy);
     }
     if ($this->progressive) {
         $pb->add('-progressive');
     }
     if (null !== $this->restart) {
         $pb->add('-restart')->add($this->restart);
     }
     $pb->add($input = FilesystemUtils::createTemporaryFile('jpegtran'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
 public function filterLoad(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->emberBin) : array($this->emberBin));
     if ($sourcePath = $asset->getSourcePath()) {
         $templateName = basename($sourcePath);
     } else {
         throw new \LogicException('The embed-precompile filter requires that assets have a source path set');
     }
     $inputDirPath = FilesystemUtils::createThrowAwayDirectory('ember_in');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName;
     $outputPath = FilesystemUtils::createTemporaryFile('ember_out');
     file_put_contents($inputPath, $asset->getContent());
     $pb->add($inputPath)->add('-f')->add($outputPath);
     $process = $pb->getProcess();
     $returnCode = $process->run();
     unlink($inputPath);
     rmdir($inputDirPath);
     if (127 === $returnCode) {
         throw new \RuntimeException('Path to node executable could not be resolved.');
     }
     if (0 !== $returnCode) {
         if (file_exists($outputPath)) {
             unlink($outputPath);
         }
         throw FilterException::fromProcess($process)->setInput($asset->getContent());
     }
     if (!file_exists($outputPath)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $compiledJs = file_get_contents($outputPath);
     unlink($outputPath);
     $asset->setContent($compiledJs);
 }
Example #3
0
 /**
  * Run the asset through UglifyJs
  *
  * @see Assetic\Filter\FilterInterface::filterDump()
  */
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->uglifycssBin) : array($this->uglifycssBin));
     if ($this->expandVars) {
         $pb->add('--expand-vars');
     }
     if ($this->uglyComments) {
         $pb->add('--ugly-comments');
     }
     if ($this->cuteComments) {
         $pb->add('--cute-comments');
     }
     // input and output files
     $input = FilesystemUtils::createTemporaryFile('uglifycss');
     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());
 }
 public function filterLoad(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->tscBin) : array($this->tscBin));
     if ($sourcePath = $asset->getSourcePath()) {
         $templateName = basename($sourcePath);
     } else {
         $templateName = 'asset';
     }
     $inputDirPath = FilesystemUtils::createThrowAwayDirectory('typescript_in');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName . '.ts';
     $outputPath = FilesystemUtils::createTemporaryFile('typescript_out');
     file_put_contents($inputPath, $asset->getContent());
     $pb->add($inputPath)->add('--out')->add($outputPath);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($inputPath);
     rmdir($inputDirPath);
     if (0 !== $code) {
         if (file_exists($outputPath)) {
             unlink($outputPath);
         }
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     if (!file_exists($outputPath)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $compiledJs = file_get_contents($outputPath);
     unlink($outputPath);
     $asset->setContent($compiledJs);
 }
Example #5
0
 public function filterLoad(AssetInterface $asset)
 {
     $builder = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->jsxBin) : array($this->jsxBin));
     $inputDir = FilesystemUtils::createThrowAwayDirectory('jsx_in');
     $inputFile = $inputDir . DIRECTORY_SEPARATOR . 'asset.js';
     $outputDir = FilesystemUtils::createThrowAwayDirectory('jsx_out');
     $outputFile = $outputDir . DIRECTORY_SEPARATOR . 'asset.js';
     // create the asset file
     file_put_contents($inputFile, $asset->getContent());
     $builder->add($inputDir)->add($outputDir)->add('--no-cache-dir');
     $proc = $builder->getProcess();
     $code = $proc->run();
     // remove the input directory and asset file
     unlink($inputFile);
     rmdir($inputDir);
     if (0 !== $code) {
         if (file_exists($outputFile)) {
             unlink($outputFile);
         }
         if (file_exists($outputDir)) {
             rmdir($outputDir);
         }
         throw FilterException::fromProcess($proc);
     }
     $asset->setContent(file_get_contents($outputFile));
     // remove the output directory and processed asset file
     unlink($outputFile);
     rmdir($outputDir);
 }
 public function filterDump(AssetInterface $asset)
 {
     $is64bit = PHP_INT_SIZE === 8;
     $cleanup = array();
     $pb = new ProcessBuilder(array_merge(array($this->javaPath), $is64bit ? array('-server', '-XX:+TieredCompilation') : array('-client', '-d32'), array('-jar', $this->jarPath)));
     if (null !== $this->timeout) {
         $pb->setTimeout($this->timeout);
     }
     if (null !== $this->compilationLevel) {
         $pb->add('--compilation_level')->add($this->compilationLevel);
     }
     if (null !== $this->jsExterns) {
         $cleanup[] = $externs = FilesystemUtils::createTemporaryFile('google_closure');
         file_put_contents($externs, $this->jsExterns);
         $pb->add('--externs')->add($externs);
     }
     if (null !== $this->externsUrl) {
         $cleanup[] = $externs = FilesystemUtils::createTemporaryFile('google_closure');
         file_put_contents($externs, file_get_contents($this->externsUrl));
         $pb->add('--externs')->add($externs);
     }
     if (null !== $this->excludeDefaultExterns) {
         $pb->add('--use_only_custom_externs');
     }
     if (null !== $this->formatting) {
         $pb->add('--formatting')->add($this->formatting);
     }
     if (null !== $this->useClosureLibrary) {
         $pb->add('--manage_closure_dependencies');
     }
     if (null !== $this->warningLevel) {
         $pb->add('--warning_level')->add($this->warningLevel);
     }
     if (null !== $this->language) {
         $pb->add('--language_in')->add($this->language);
     }
     if (null !== $this->flagFile) {
         $pb->add('--flagfile')->add($this->flagFile);
     }
     $pb->add('--js')->add($cleanup[] = $input = FilesystemUtils::createTemporaryFile('google_closure'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     array_map('unlink', $cleanup);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
 public function filterLoad(AssetInterface $asset)
 {
     $input = $asset->getContent();
     $pb = $this->createProcessBuilder(array($this->autoprefixerBin));
     $pb->setInput($input);
     if ($this->browsers) {
         $pb->add('-b')->add(implode(',', $this->browsers));
     }
     $output = FilesystemUtils::createTemporaryFile('autoprefixer');
     $pb->add('-o')->add($output);
     $proc = $pb->getProcess();
     if (0 !== $proc->run()) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }
Example #8
0
    public function filterLoad(AssetInterface $asset)
    {
        static $manifest = <<<EOF
name: Application%s
sources: [source.js]

EOF;
        $hash = substr(sha1(time() . rand(11111, 99999)), 0, 7);
        $package = FilesystemUtils::getTemporaryDirectory() . '/assetic_packager_' . $hash;
        mkdir($package);
        file_put_contents($package . '/package.yml', sprintf($manifest, $hash));
        file_put_contents($package . '/source.js', $asset->getContent());
        $packager = new \Packager(array_merge(array($package), $this->packages));
        $content = $packager->build(array(), array(), array('Application' . $hash));
        unlink($package . '/package.yml');
        unlink($package . '/source.js');
        rmdir($package);
        $asset->setContent($content);
    }
 public function filterLoad(AssetInterface $asset)
 {
     $input = FilesystemUtils::createTemporaryFile('dart');
     $output = FilesystemUtils::createTemporaryFile('dart');
     file_put_contents($input, $asset->getContent());
     $pb = $this->createProcessBuilder()->add($this->dartBin)->add('-o' . $output)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         $this->cleanup($output);
         throw FilterException::fromProcess($proc);
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $asset->setContent(file_get_contents($output));
     $this->cleanup($output);
 }
Example #10
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->optipngBin));
     if (null !== $this->level) {
         $pb->add('-o')->add($this->level);
     }
     $pb->add('-out')->add($output = FilesystemUtils::createTemporaryFile('optipng_out'));
     unlink($output);
     $pb->add($input = FilesystemUtils::createTemporaryFile('optinpg_in'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 !== $code) {
         unlink($input);
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($input);
     unlink($output);
 }
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->jpegoptimBin));
     if ($this->stripAll) {
         $pb->add('--strip-all');
     }
     if ($this->max) {
         $pb->add('--max=' . $this->max);
     }
     $pb->add($input = FilesystemUtils::createTemporaryFile('jpegoptim'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $proc->run();
     if (false !== strpos($proc->getOutput(), 'ERROR')) {
         unlink($input);
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($input));
     unlink($input);
 }
Example #12
0
 public function filterLoad(AssetInterface $asset)
 {
     $input = FilesystemUtils::createTemporaryFile('coffee');
     file_put_contents($input, $asset->getContent());
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->coffeeBin) : array($this->coffeeBin));
     $pb->add('-cp');
     if ($this->bare) {
         $pb->add('--bare');
     }
     if ($this->noHeader) {
         $pb->add('--no-header');
     }
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
    /**
     * Hack around a bit, get the job done.
     */
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
#!/usr/bin/env ruby

require %s
%s
options = { :load_path    => [],
            :source_files => [%s],
            :expand_paths => false }

%ssecretary = Sprockets::Secretary.new(options)
secretary.install_assets if options[:asset_root]
print secretary.concatenation

EOF;
        $more = '';
        foreach ($this->includeDirs as $directory) {
            $more .= 'options[:load_path] << ' . var_export($directory, true) . "\n";
        }
        if (null !== $this->assetRoot) {
            $more .= 'options[:asset_root] = ' . var_export($this->assetRoot, true) . "\n";
        }
        if ($more) {
            $more .= "\n";
        }
        $tmpAsset = FilesystemUtils::createTemporaryFile('sprockets_asset');
        file_put_contents($tmpAsset, $asset->getContent());
        $input = FilesystemUtils::createTemporaryFile('sprockets_in');
        file_put_contents($input, sprintf($format, $this->sprocketsLib ? sprintf('File.join(%s, \'sprockets\')', var_export($this->sprocketsLib, true)) : '\'sprockets\'', $this->getHack($asset), var_export($tmpAsset, true), $more));
        $pb = $this->createProcessBuilder(array($this->rubyBin, $input));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($tmpAsset);
        unlink($input);
        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
        $asset->setContent($proc->getOutput());
    }
Example #14
0
 public function filterLoad(AssetInterface $asset)
 {
     $input = FilesystemUtils::createTemporaryFile('roole');
     $output = $input . '.css';
     file_put_contents($input, $asset->getContent());
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->rooleBin) : array($this->rooleBin));
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         throw FilterException::fromProcess($proc);
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }
Example #15
0
 /**
  * Compresses a string.
  *
  * @param string $content The content to compress
  * @param string $type    The type of content, either "js" or "css"
  * @param array  $options An indexed array of additional options
  *
  * @return string The compressed content
  */
 protected function compress($content, $type, $options = array())
 {
     $pb = $this->createProcessBuilder(array($this->javaPath));
     if (null !== $this->stackSize) {
         $pb->add('-Xss' . $this->stackSize);
     }
     $pb->add('-jar')->add($this->jarPath);
     foreach ($options as $option) {
         $pb->add($option);
     }
     if (null !== $this->charset) {
         $pb->add('--charset')->add($this->charset);
     }
     if (null !== $this->lineBreak) {
         $pb->add('--line-break')->add($this->lineBreak);
     }
     // input and output files
     $tempDir = FilesystemUtils::getTemporaryDirectory();
     $input = tempnam($tempDir, 'assetic_yui_input');
     $output = tempnam($tempDir, 'assetic_yui_output');
     file_put_contents($input, $content);
     $pb->add('-o')->add($output)->add('--type')->add($type)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         throw FilterException::fromProcess($proc)->setInput($content);
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $retval = file_get_contents($output);
     unlink($output);
     return $retval;
 }
    /**
     * {@inheritdoc}
     */
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
var stylus = require('stylus');
var sys    = require(process.binding('natives').util ? 'util' : 'sys');

stylus(%s, %s)%s.render(function(e, css){
    if (e) {
        throw e;
    }

    sys.print(css);
    process.exit(0);
});

EOF;
        // parser options
        $parserOptions = array();
        if ($dir = $asset->getSourceDirectory()) {
            $parserOptions['paths'] = array($dir);
            $parserOptions['filename'] = basename($asset->getSourcePath());
        }
        if (null !== $this->compress) {
            $parserOptions['compress'] = $this->compress;
        }
        $pb = $this->createProcessBuilder();
        $pb->add($this->nodeBin)->add($input = FilesystemUtils::createTemporaryFile('stylus'));
        file_put_contents($input, sprintf($format, json_encode($asset->getContent()), json_encode($parserOptions), $this->useNib ? '.use(require(\'nib\')())' : ''));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);
        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
        $asset->setContent($proc->getOutput());
    }
 /**
  * Run the asset through UglifyJs
  *
  * @see Assetic\Filter\FilterInterface::filterDump()
  */
 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');
     }
     if ($this->defines) {
         foreach ($this->defines as $define) {
             $pb->add('-d')->add($define);
         }
     }
     // input and output files
     $input = FilesystemUtils::createTemporaryFile('uglifyjs_in');
     $output = FilesystemUtils::createTemporaryFile('uglifyjs_out');
     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);
 }
 private function processCall($call, array $protoOptions = array())
 {
     $tmp = FilesystemUtils::createTemporaryFile('php_formula_loader');
     file_put_contents($tmp, implode("\n", array('<?php', $this->registerSetupCode(), $call, 'echo serialize($_call);')));
     $args = unserialize(shell_exec('php ' . escapeshellarg($tmp)));
     unlink($tmp);
     $inputs = isset($args[0]) ? self::argumentToArray($args[0]) : array();
     $filters = isset($args[1]) ? self::argumentToArray($args[1]) : array();
     $options = isset($args[2]) ? $args[2] : array();
     if (!isset($options['debug'])) {
         $options['debug'] = $this->factory->isDebug();
     }
     if (!is_array($options)) {
         throw new \RuntimeException('The third argument must be omitted, null or an array.');
     }
     // apply the prototype options
     $options += $protoOptions;
     if (!isset($options['name'])) {
         $options['name'] = $this->factory->generateAssetName($inputs, $filters, $options);
     }
     return array($options['name'] => array($inputs, $filters, $options));
 }
 public function filterLoad(AssetInterface $asset)
 {
     $loadPaths = $this->loadPaths;
     if ($dir = $asset->getSourceDirectory()) {
         $loadPaths[] = $dir;
     }
     $tempDir = $this->cacheLocation ? $this->cacheLocation : FilesystemUtils::getTemporaryDirectory();
     $compassProcessArgs = array($this->compassPath, 'compile', $tempDir);
     if (null !== $this->rubyPath) {
         $compassProcessArgs = array_merge(explode(' ', $this->rubyPath), $compassProcessArgs);
     }
     $pb = $this->createProcessBuilder($compassProcessArgs);
     if ($this->force) {
         $pb->add('--force');
     }
     if ($this->style) {
         $pb->add('--output-style')->add($this->style);
     }
     if ($this->quiet) {
         $pb->add('--quiet');
     }
     if ($this->boring) {
         $pb->add('--boring');
     }
     if ($this->noLineComments) {
         $pb->add('--no-line-comments');
     }
     // these three options are not passed into the config file
     // because like this, compass adapts this to be xxx_dir or xxx_path
     // whether it's an absolute path or not
     if ($this->imagesDir) {
         $pb->add('--images-dir')->add($this->imagesDir);
     }
     if ($this->relativeAssets) {
         $pb->add('--relative-assets');
     }
     if ($this->javascriptsDir) {
         $pb->add('--javascripts-dir')->add($this->javascriptsDir);
     }
     if ($this->fontsDir) {
         $pb->add('--fonts-dir')->add($this->fontsDir);
     }
     // options in config file
     $optionsConfig = array();
     if (!empty($loadPaths)) {
         $optionsConfig['additional_import_paths'] = $loadPaths;
     }
     if ($this->unixNewlines) {
         $optionsConfig['sass_options']['unix_newlines'] = true;
     }
     if ($this->debugInfo) {
         $optionsConfig['sass_options']['debug_info'] = true;
     }
     if ($this->cacheLocation) {
         $optionsConfig['sass_options']['cache_location'] = $this->cacheLocation;
     }
     if ($this->noCache) {
         $optionsConfig['sass_options']['no_cache'] = true;
     }
     if ($this->httpPath) {
         $optionsConfig['http_path'] = $this->httpPath;
     }
     if ($this->httpImagesPath) {
         $optionsConfig['http_images_path'] = $this->httpImagesPath;
     }
     if ($this->httpFontsPath) {
         $optionsConfig['http_fonts_path'] = $this->httpFontsPath;
     }
     if ($this->httpGeneratedImagesPath) {
         $optionsConfig['http_generated_images_path'] = $this->httpGeneratedImagesPath;
     }
     if ($this->generatedImagesPath) {
         $optionsConfig['generated_images_path'] = $this->generatedImagesPath;
     }
     if ($this->httpJavascriptsPath) {
         $optionsConfig['http_javascripts_path'] = $this->httpJavascriptsPath;
     }
     // options in configuration file
     if (count($optionsConfig)) {
         $config = array();
         foreach ($this->plugins as $plugin) {
             $config[] = sprintf("require '%s'", addcslashes($plugin, '\\'));
         }
         foreach ($optionsConfig as $name => $value) {
             if (!is_array($value)) {
                 $config[] = sprintf('%s = "%s"', $name, addcslashes($value, '\\'));
             } elseif (!empty($value)) {
                 $config[] = sprintf('%s = %s', $name, $this->formatArrayToRuby($value));
             }
         }
         $configFile = tempnam($tempDir, 'assetic_compass');
         file_put_contents($configFile, implode("\n", $config) . "\n");
         $pb->add('--config')->add($configFile);
     }
     $pb->add('--sass-dir')->add('')->add('--css-dir')->add('');
     // compass choose the type (sass or scss from the filename)
     if (null !== $this->scss) {
         $type = $this->scss ? 'scss' : 'sass';
     } elseif ($path = $asset->getSourcePath()) {
         // FIXME: what if the extension is something else?
         $type = pathinfo($path, PATHINFO_EXTENSION);
     } else {
         $type = 'scss';
     }
     $tempName = tempnam($tempDir, 'assetic_compass');
     unlink($tempName);
     // FIXME: don't use tempnam() here
     // input
     $input = $tempName . '.' . $type;
     // work-around for https://github.com/chriseppstein/compass/issues/748
     if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
         $input = str_replace('\\', '/', $input);
     }
     $pb->add($input);
     file_put_contents($input, $asset->getContent());
     // output
     $output = $tempName . '.css';
     if ($this->homeEnv) {
         // it's not really usefull but... https://github.com/chriseppstein/compass/issues/376
         $pb->setEnv('HOME', FilesystemUtils::getTemporaryDirectory());
         $this->mergeEnv($pb);
     }
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 !== $code) {
         unlink($input);
         if (isset($configFile)) {
             unlink($configFile);
         }
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($input);
     unlink($output);
     if (isset($configFile)) {
         unlink($configFile);
     }
 }
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->pngoutBin));
     if (null !== $this->color) {
         $pb->add('-c' . $this->color);
     }
     if (null !== $this->filter) {
         $pb->add('-f' . $this->filter);
     }
     if (null !== $this->strategy) {
         $pb->add('-s' . $this->strategy);
     }
     if (null !== $this->blockSplitThreshold) {
         $pb->add('-b' . $this->blockSplitThreshold);
     }
     $pb->add($input = FilesystemUtils::createTemporaryFile('pngout_in'));
     file_put_contents($input, $asset->getContent());
     $output = FilesystemUtils::createTemporaryFile('pngout_out');
     unlink($output);
     $pb->add($output .= '.png');
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 !== $code) {
         unlink($input);
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($input);
     unlink($output);
 }
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
     if (null !== $this->charset) {
         $pb->add('--charset')->add($this->charset);
     }
     if ($this->mhtml) {
         $pb->add('--mhtml');
     }
     if (null !== $this->mhtmlRoot) {
         $pb->add('--mhtmlroot')->add($this->mhtmlRoot);
     }
     // automatically define root if not already defined
     if (null === $this->root) {
         if ($dir = $asset->getSourceDirectory()) {
             $pb->add('--root')->add($dir);
         }
     } else {
         $pb->add('--root')->add($this->root);
     }
     if ($this->skipMissing) {
         $pb->add('--skip-missing');
     }
     if (null !== $this->maxUriLength) {
         $pb->add('--max-uri-length')->add($this->maxUriLength);
     }
     if (null !== $this->maxImageSize) {
         $pb->add('--max-image-size')->add($this->maxImageSize);
     }
     // input
     $pb->add($input = FilesystemUtils::createTemporaryFile('cssembed'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
 public function filterLoad(AssetInterface $asset)
 {
     $cleanup = array();
     $pb = $this->createProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
     if (null !== $this->allowUnrecognizedFunctions) {
         $pb->add('--allow-unrecognized-functions');
     }
     if (null !== $this->allowedNonStandardFunctions) {
         $pb->add('--allowed_non_standard_functions')->add($this->allowedNonStandardFunctions);
     }
     if (null !== $this->copyrightNotice) {
         $pb->add('--copyright-notice')->add($this->copyrightNotice);
     }
     if (null !== $this->define) {
         $pb->add('--define')->add($this->define);
     }
     if (null !== $this->gssFunctionMapProvider) {
         $pb->add('--gss-function-map-provider')->add($this->gssFunctionMapProvider);
     }
     if (null !== $this->inputOrientation) {
         $pb->add('--input-orientation')->add($this->inputOrientation);
     }
     if (null !== $this->outputOrientation) {
         $pb->add('--output-orientation')->add($this->outputOrientation);
     }
     if (null !== $this->prettyPrint) {
         $pb->add('--pretty-print');
     }
     $pb->add($cleanup[] = $input = FilesystemUtils::createTemporaryFile('gss'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     array_map('unlink', $cleanup);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
Example #23
0
 public function filterLoad(AssetInterface $asset)
 {
     $sassProcessArgs = array($this->sassPath);
     if (null !== $this->rubyPath) {
         $sassProcessArgs = array_merge(explode(' ', $this->rubyPath), $sassProcessArgs);
     }
     $pb = $this->createProcessBuilder($sassProcessArgs);
     if ($dir = $asset->getSourceDirectory()) {
         $pb->add('--load-path')->add($dir);
     }
     if ($this->unixNewlines) {
         $pb->add('--unix-newlines');
     }
     if (true === $this->scss || null === $this->scss && 'scss' == pathinfo($asset->getSourcePath(), PATHINFO_EXTENSION)) {
         $pb->add('--scss');
     }
     if ($this->style) {
         $pb->add('--style')->add($this->style);
     }
     if ($this->precision) {
         $pb->add('--precision')->add($this->precision);
     }
     if ($this->quiet) {
         $pb->add('--quiet');
     }
     if ($this->debugInfo) {
         $pb->add('--debug-info');
     }
     if ($this->lineNumbers) {
         $pb->add('--line-numbers');
     }
     if ($this->sourceMap) {
         $pb->add('--sourcemap');
     }
     foreach ($this->loadPaths as $loadPath) {
         $pb->add('--load-path')->add($loadPath);
     }
     if ($this->cacheLocation) {
         $pb->add('--cache-location')->add($this->cacheLocation);
     }
     if ($this->noCache) {
         $pb->add('--no-cache');
     }
     if ($this->compass) {
         $pb->add('--compass');
     }
     // input
     $pb->add($input = FilesystemUtils::createTemporaryFile('sass'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
Example #24
0
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
var less = require('less');
var sys  = require(process.binding('natives').util ? 'util' : 'sys');

less.render(%s, %s, function(error, css) {
    if (error) {
        less.writeError(error);
        process.exit(2);
    }
    try {
        if (typeof css == 'string') {
            sys.print(css);
        } else {
            sys.print(css.css);
        }
    } catch (e) {
        less.writeError(error);
        process.exit(3);
    }
});

EOF;
        // parser options
        $parserOptions = $this->parserOptions;
        if ($dir = $asset->getSourceDirectory()) {
            $parserOptions['paths'] = array($dir);
            $parserOptions['filename'] = basename($asset->getSourcePath());
        }
        foreach ($this->loadPaths as $loadPath) {
            $parserOptions['paths'][] = $loadPath;
        }
        $pb = $this->createProcessBuilder();
        $pb->add($this->nodeBin)->add($input = FilesystemUtils::createTemporaryFile('less'));
        file_put_contents($input, sprintf($format, json_encode($asset->getContent()), json_encode(array_merge($parserOptions, $this->treeOptions))));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);
        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
        $asset->setContent($proc->getOutput());
    }
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->uglifyjsBin) : array($this->uglifyjsBin));
     if ($this->compress) {
         $pb->add('--compress');
         if (is_string($this->compress) && !empty($this->compress)) {
             $pb->add($this->compress);
         }
     }
     if ($this->beautify) {
         $pb->add('--beautify');
     }
     if ($this->mangle) {
         $pb->add('--mangle');
     }
     if ($this->screwIe8) {
         $pb->add('--screw-ie8');
     }
     if ($this->comments) {
         $pb->add('--comments')->add(true === $this->comments ? 'all' : $this->comments);
     }
     if ($this->wrap) {
         $pb->add('--wrap')->add($this->wrap);
     }
     if ($this->defines) {
         $pb->add('--define')->add(implode(',', $this->defines));
     }
     // input and output files
     $input = FilesystemUtils::createTemporaryFile('uglifyjs2_in');
     $output = FilesystemUtils::createTemporaryFile('uglifyjs2_out');
     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.');
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }