Source of file CompilerJarFilter.php
Size: 2,865 Bytes - Last Modified: 2013-06-02T00:13:43+02:00
/home/theseer/Downloads/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/GoogleClosure/CompilerJarFilter.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | <?php /* * This file is part of the Assetic package, an OpenSky project. * * (c) 2010-2013 OpenSky Project Inc * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Assetic\Filter\GoogleClosure; use Assetic\Asset\AssetInterface; use Assetic\Exception\FilterException; use Symfony\Component\Process\ProcessBuilder; /** * Filter for the Google Closure Compiler JAR. * * @link https://developers.google.com/closure/compiler/ * @author Kris Wallsmith <kris.wallsmith@gmail.com> */ class CompilerJarFilter extends BaseCompilerFilter { private $jarPath; private $javaPath; public function __construct($jarPath, $javaPath = '/usr/bin/java') { $this->jarPath = $jarPath; $this->javaPath = $javaPath; } public function filterDump(AssetInterface $asset) { $cleanup = array(); $pb = new ProcessBuilder(array( $this->javaPath, '-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); } $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()); } } |