class CompilerJarFilter

Filter for the Google Closure Compiler JAR.

@link https://developers.google.com/closure/compiler/ @author Kris Wallsmith <kris.wallsmith@gmail.com>

Hierarchy

Expanded class hierarchy of CompilerJarFilter

1 file declares its use of CompilerJarFilter
CompilerJarFilterTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Filter/GoogleClosure/CompilerJarFilterTest.php

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/GoogleClosure/CompilerJarFilter.php, line 24

Namespace

Assetic\Filter\GoogleClosure
View source
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->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());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseCompilerFilter::$compilationLevel protected property
BaseCompilerFilter::$excludeDefaultExterns protected property
BaseCompilerFilter::$externsUrl protected property
BaseCompilerFilter::$formatting protected property
BaseCompilerFilter::$jsExterns protected property
BaseCompilerFilter::$language protected property
BaseCompilerFilter::$useClosureLibrary protected property
BaseCompilerFilter::$warningLevel protected property
BaseCompilerFilter::COMPILE_ADVANCED_OPTIMIZATIONS constant
BaseCompilerFilter::COMPILE_SIMPLE_OPTIMIZATIONS constant
BaseCompilerFilter::COMPILE_WHITESPACE_ONLY constant
BaseCompilerFilter::filterLoad public function Filters an asset after it has been loaded. Overrides FilterInterface::filterLoad
BaseCompilerFilter::FORMAT_PRETTY_PRINT constant
BaseCompilerFilter::FORMAT_PRINT_INPUT_DELIMITER constant
BaseCompilerFilter::LANGUAGE_ECMASCRIPT3 constant
BaseCompilerFilter::LANGUAGE_ECMASCRIPT5 constant
BaseCompilerFilter::LANGUAGE_ECMASCRIPT5_STRICT constant
BaseCompilerFilter::LEVEL_DEFAULT constant
BaseCompilerFilter::LEVEL_QUIET constant
BaseCompilerFilter::LEVEL_VERBOSE constant
BaseCompilerFilter::setCompilationLevel public function
BaseCompilerFilter::setExcludeDefaultExterns public function
BaseCompilerFilter::setExternsUrl public function
BaseCompilerFilter::setFormatting public function
BaseCompilerFilter::setJsExterns public function
BaseCompilerFilter::setLanguage public function
BaseCompilerFilter::setUseClosureLibrary public function
BaseCompilerFilter::setWarningLevel public function
CompilerJarFilter::$jarPath private property
CompilerJarFilter::$javaPath private property
CompilerJarFilter::filterDump public function Filters an asset just before it's dumped. Overrides FilterInterface::filterDump
CompilerJarFilter::__construct public function