class CssEmbedFilter

CSSEmbed filter

@link https://github.com/nzakas/cssembed @author Maxime Thirouin <maxime.thirouin@gmail.com>

Hierarchy

Expanded class hierarchy of CssEmbedFilter

1 file declares its use of CssEmbedFilter
CssEmbedFilterTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Filter/CssEmbedFilterTest.php

File

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

Namespace

Assetic\Filter
View source
class CssEmbedFilter implements FilterInterface {
  private $jarPath;
  private $javaPath;
  private $charset;
  private $mhtml;

  // Enable MHTML mode.
  private $mhtmlRoot;

  // Use <root> as the MHTML root for the file.
  private $root;

  // Prepends <root> to all relative URLs.
  private $skipMissing;

  // Don't throw an error for missing image files.
  private $maxUriLength;

  // Maximum length for a data URI. Defaults to 32768.
  private $maxImageSize;

  // Maximum image size (in bytes) to convert.
  public function __construct($jarPath, $javaPath = '/usr/bin/java') {
    $this->jarPath = $jarPath;
    $this->javaPath = $javaPath;
  }
  public function setCharset($charset) {
    $this->charset = $charset;
  }
  public function setMhtml($mhtml) {
    $this->mhtml = $mhtml;
  }
  public function setMhtmlRoot($mhtmlRoot) {
    $this->mhtmlRoot = $mhtmlRoot;
  }
  public function setRoot($root) {
    $this->root = $root;
  }
  public function setSkipMissing($skipMissing) {
    $this->skipMissing = $skipMissing;
  }
  public function setMaxUriLength($maxUriLength) {
    $this->maxUriLength = $maxUriLength;
  }
  public function setMaxImageSize($maxImageSize) {
    $this->maxImageSize = $maxImageSize;
  }
  public function filterLoad(AssetInterface $asset) {
  }
  public function filterDump(AssetInterface $asset) {
    $pb = new ProcessBuilder(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) {
      $root = $asset
        ->getSourceRoot();
      $path = $asset
        ->getSourcePath();
      if ($root && $path) {
        $pb
          ->add('--root')
          ->add(dirname($root . '/' . $path));
      }
    }
    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 = tempnam(sys_get_temp_dir(), 'assetic_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());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CssEmbedFilter::$charset private property
CssEmbedFilter::$jarPath private property
CssEmbedFilter::$javaPath private property
CssEmbedFilter::$maxImageSize private property
CssEmbedFilter::$maxUriLength private property
CssEmbedFilter::$mhtml private property
CssEmbedFilter::$mhtmlRoot private property
CssEmbedFilter::$root private property
CssEmbedFilter::$skipMissing private property
CssEmbedFilter::filterDump public function Filters an asset just before it's dumped. Overrides FilterInterface::filterDump
CssEmbedFilter::filterLoad public function Filters an asset after it has been loaded. Overrides FilterInterface::filterLoad
CssEmbedFilter::setCharset public function
CssEmbedFilter::setMaxImageSize public function
CssEmbedFilter::setMaxUriLength public function
CssEmbedFilter::setMhtml public function
CssEmbedFilter::setMhtmlRoot public function
CssEmbedFilter::setRoot public function
CssEmbedFilter::setSkipMissing public function
CssEmbedFilter::__construct public function