public function UglifyCssFilter::filterDump

Run the asset through UglifyJs

Overrides FilterInterface::filterDump

See also

Assetic\Filter\FilterInterface::filterDump()

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/UglifyCssFilter.php, line 81

Class

UglifyCssFilter
UglifyCss filter.

Namespace

Assetic\Filter

Code

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 = 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());
}