protected function compress(AssetInterface $asset, $type, $options = array())
 {
     $pb = $this->createProcessBuilder(array($this->javaPath));
     $pb->add('-jar')->add($this->jarPath);
     foreach ($options as $option) {
         $pb->add($option);
     }
     $this->charset and $pb->add('--charset')->add($this->charset);
     $this->preserveComments and $pb->add('--preserve-comments');
     $this->removeIntertagSpaces and $pb->add('--remove-intertag-spaces');
     // input and output files
     $tempDir = realpath(sys_get_temp_dir());
     $input = tempnam($tempDir, 'assetic_htmlcompressor');
     $output = tempnam($tempDir, 'assetic_htmlcompressor');
     file_put_contents($input, $asset->getContent());
     $pb->add('-o')->add($output)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code || false !== strpos($proc->getOutput(), 'ERROR')) {
         if (file_exists($output)) {
             unlink($output);
         }
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }
 /**
  * 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 = new ProcessBuilder(array($this->javaPath, '-jar', $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 = realpath(sys_get_temp_dir());
     $hash = substr(sha1(time() . rand(11111, 99999)), 0, 7);
     $input = $tempDir . DIRECTORY_SEPARATOR . $hash . '.' . $type;
     $output = $tempDir . DIRECTORY_SEPARATOR . $hash . '-min.' . $type;
     file_put_contents($input, $content);
     $pb->add('-o')->add($output)->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);
     } elseif (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $retval = file_get_contents($output);
     unlink($output);
     return $retval;
 }
Example #3
0
 public function filterLoad(AssetInterface $asset)
 {
     $sassProcessArgs = array($this->binaryPath);
     $pb = $this->createProcessBuilder($sassProcessArgs);
     $pb->add('--stdout');
     $assetDirectory = '';
     if (method_exists($asset, 'getSourceDirectory')) {
         $assetDirectory = $asset->getSourceDirectory();
     } else {
         $root = $asset->getSourceRoot();
         $path = $asset->getSourcePath();
         $assetDirectory = dirname($root . '/' . $path);
     }
     $allLoadPaths = $this->loadPaths;
     array_unshift($allLoadPaths, $assetDirectory);
     $pb->add('--include-path')->add(implode(':', $allLoadPaths));
     if ($this->style) {
         $pb->add('--output-style')->add($this->style);
     }
     if ($this->sourceComments) {
         $pb->add('--source-comments')->add($this->sourceComments);
     }
     if ($this->emitSourceMap) {
         $pb->add('--source-map');
     }
     $pb->add($asset->getSourceRoot() . '/' . $asset->getSourcePath());
     $pb->add(storage_path() . '/cache/sassc');
     $process = $pb->getProcess();
     $code = $process->run();
     if (0 !== $code) {
         throw FilterException::fromProcess($process);
     }
     $asset->setContent($process->getOutput());
 }
 public function filterLoad(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->emberBin) : array($this->emberBin));
     $templateName = basename($asset->getSourcePath());
     $inputDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('input_dir');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName;
     $outputPath = tempnam(sys_get_temp_dir(), 'output');
     mkdir($inputDirPath);
     file_put_contents($inputPath, $asset->getContent());
     $pb->add($inputPath)->add('-f')->add($outputPath);
     if ($this->includeBaseDir) {
         $pb->add('-b')->add($inputDirPath . DIRECTORY_SEPARATOR);
     }
     $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);
 }
 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 ($this->beautify) {
         $pb->add('--beautify');
     }
     if ($this->mangle) {
         $pb->add('--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.');
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }
 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 = tempnam(sys_get_temp_dir(), 'assetic_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());
 }
Example #7
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 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);
 }
 public function filterLoad(AssetInterface $asset)
 {
     $sassProcessArgs = array();
     if (null !== $this->nodePath) {
         $sassProcessArgs[] = $this->nodePath;
     }
     $sassProcessArgs[] = $this->sassPath;
     $pb = $this->createProcessBuilder($sassProcessArgs);
     if ($dir = $asset->getSourceDirectory()) {
         $pb->add('--include-path')->add($dir);
     }
     if ($this->style) {
         $pb->add('--output-style')->add($this->style);
     }
     if ($this->sourceMap) {
         $pb->add('--source-map');
     }
     if ($this->debugInfo) {
         $pb->add('--source-comments');
     }
     foreach ($this->loadPaths as $loadPath) {
         $pb->add('--include-path')->add($loadPath);
     }
     // input
     $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_sass'));
     file_put_contents($input, $asset->getContent());
     $pb->add('--stdout');
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
 /**
  * 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, '-jar', $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 = realpath(sys_get_temp_dir());
     $input = tempnam($tempDir, 'YUI-IN-');
     $output = tempnam($tempDir, 'YUI-OUT-');
     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;
 }
 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 #12
0
 /**
  * Filters an asset just before it's dumped.
  *
  * @param AssetInterface $asset An asset
  */
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->cssoPath) : array($this->cssoPath));
     // 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('-i')->add($input);
     $pb->add('-o')->add($output);
     $process = $pb->getProcess();
     $code = $process->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($process)->setInput($asset->getContent());
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $csso = file_get_contents($output);
     unlink($output);
     $asset->setContent($csso);
 }
 /**
  * Filters an asset just before it's dumped.
  *
  * @param AssetInterface $asset An asset
  */
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->htmlMinifierBin) : array($this->htmlMinifierBin));
     // input and output files
     $input = tempnam(sys_get_temp_dir(), 'input');
     $output = tempnam(sys_get_temp_dir(), 'output');
     file_put_contents($input, $asset->getContent());
     foreach ($this->getOptions() as $option) {
         $pb->add('--' . $option);
     }
     $pb->add('--output');
     $pb->add($output);
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         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);
 }
Example #14
0
 public function filterLoad(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->tscBin) : array($this->tscBin));
     $templateName = basename($asset->getSourcePath());
     $inputDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('input_dir');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName . '.ts';
     $outputPath = tempnam(sys_get_temp_dir(), 'output');
     mkdir($inputDirPath);
     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);
 }
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->ttf2eotBin));
     $input = tempnam(sys_get_temp_dir(), 'assetic_ttf2eot');
     file_put_contents($input, $asset->getContent());
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if ($code !== 0) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
 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 = tempnam(sys_get_temp_dir(), 'assetic_google_closure_compiler');
         file_put_contents($externs, $this->jsExterns);
         $pb->add('--externs')->add($externs);
     }
     if (null !== $this->externsUrl) {
         $cleanup[] = $externs = tempnam(sys_get_temp_dir(), 'assetic_google_closure_compiler');
         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 = tempnam(sys_get_temp_dir(), 'assetic_google_closure_compiler'));
     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 #17
0
 public function filterLoad(AssetInterface $asset)
 {
     $input = tempnam(sys_get_temp_dir(), 'assetic_roole');
     file_put_contents($input, $asset->getContent());
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->rooleBin) : array($this->rooleBin));
     $pb->add('-p');
     $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());
 }
Example #18
0
 public function filterLoad(AssetInterface $asset)
 {
     $input = tempnam(sys_get_temp_dir(), 'assetic_coffeescript');
     file_put_contents($input, $asset->getContent());
     $pb = new ProcessBuilder(array($this->nodePath, $this->coffeePath, '-cp'));
     if ($this->bare) {
         $pb->add('--bare');
     }
     $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());
 }
Example #19
0
 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 = tempnam(sys_get_temp_dir(), 'assetic_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);
 }
 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 #21
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 = tempnam(sys_get_temp_dir(), 'assetic_optipng'));
     unlink($output);
     $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_optipng'));
     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);
 }
Example #22
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);
 }
Example #23
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = new ProcessBuilder(array($this->jpegoptimBin));
     if ($this->stripAll) {
         $pb->add('--strip-all');
     }
     if ($this->max) {
         $pb->add('--max=' . $this->max);
     }
     $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_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);
 }
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->fontforgeBin));
     $input = tempnam(sys_get_temp_dir(), 'assetic_fontforge');
     $output = sys_get_temp_dir() . '/' . basename($input, '.tmp') . '.' . $this->format;
     file_put_contents($input, $asset->getContent());
     $pb->add('-lang=ff');
     $pb->add('-c');
     $pb->add('Open($1); Generate($2);');
     $pb->add($input);
     $pb->add($output);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if ($code !== 0) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }
 public function filterLoad(AssetInterface $asset)
 {
     $executables = array();
     if ($this->nodePath !== null) {
         $executables[] = $this->nodePath;
     }
     $executables[] = $this->handlebarsPath;
     $processBuilder = new ProcessBuilder($executables);
     $templateName = basename($asset->getSourcePath());
     $inputDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('input_dir');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName;
     $outputPath = tempnam(sys_get_temp_dir(), 'output');
     mkdir($inputDirPath);
     file_put_contents($inputPath, $asset->getContent());
     $processBuilder->add($inputPath)->add('-f')->add($outputPath);
     if ($this->minimize) {
         $processBuilder->add('--min');
     }
     if ($this->simple) {
         $processBuilder->add('--simple');
     }
     $process = $processBuilder->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 #26
0
 public function filterLoad(AssetInterface $asset)
 {
     $input = tempnam(sys_get_temp_dir(), 'assetic_dart');
     $output = tempnam(sys_get_temp_dir(), 'assetic_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) {
         if (file_exists($output)) {
             unlink($output);
         }
         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);
 }
Example #27
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());
 }
Example #28
0
 /**
  * Apply filter on file load.
  *
  * @param  \Assetic\Asset\AssetInterface  $asset
  * @return void
  */
 public function filterLoad(AssetInterface $asset)
 {
     $inputFile = tempnam(sys_get_temp_dir(), 'csso');
     file_put_contents($inputFile, $asset->getContent());
     // Before we create our process builder we'll create the arguments to be given to the builder.
     // If we have a node bin supplied then we'll shift that to the beginning of the array.
     $builderArguments = array($this->cssoBin);
     if (!is_null($this->nodeBin)) {
         array_unshift($builderArguments, $this->nodeBin);
     }
     $builder = $this->createProcessBuilder($builderArguments);
     $builder->add($inputFile);
     // Get the process from the builder and run the process.
     $process = $builder->getProcess();
     $code = $process->run();
     unlink($inputFile);
     if ($code !== 0) {
         throw FilterException::fromProcess($process)->setInput($asset->getContent());
     }
     $asset->setContent($process->getOutput());
 }
Example #29
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->lesscBin));
     if ($this->compress) {
         $pb->add('--compress');
     }
     if (!$this->ieCompat) {
         $pb->add('--no-ie-compat');
     }
     if ($this->sourceMap) {
         // TODO: Figure out how to place the generated file.
         //$pb->add('--source-map');
     }
     if (($root = $asset->getSourceRoot()) && ($path = $asset->getSourcePath())) {
         $pb->add('--include-path=' . dirname($root . '/' . $path));
     }
     // 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($input)->add($output);
     $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);
 }
Example #30
0
    /**
     * {@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).render(function(e, css){
    if (e) {
        throw e;
    }

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

EOF;
        $root = $asset->getSourceRoot();
        $path = $asset->getSourcePath();
        // parser options
        $parserOptions = array();
        if ($root && $path) {
            $parserOptions['paths'] = array(dirname($root . '/' . $path));
            $parserOptions['filename'] = basename($path);
        }
        if (null !== $this->compress) {
            $parserOptions['compress'] = $this->compress;
        }
        $pb = $this->createProcessBuilder();
        $pb->inheritEnvironmentVariables();
        $pb->add($this->nodeBin)->add($input = tempnam(sys_get_temp_dir(), 'assetic_stylus'));
        file_put_contents($input, sprintf($format, json_encode($asset->getContent()), json_encode($parserOptions)));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);
        if (0 < $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
        $asset->setContent($proc->getOutput());
    }