abstract class BaseCssFilter

An abstract filter for dealing with CSS.

@author Kris Wallsmith <kris.wallsmith@gmail.com>

Hierarchy

Expanded class hierarchy of BaseCssFilter

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/BaseCssFilter.php, line 19

Namespace

Assetic\Filter
View source
abstract class BaseCssFilter implements FilterInterface {

  /**
   * Filters all references -- url() and "@import" -- through a callable.
   *
   * @param string $content  The CSS
   * @param mixed  $callback A PHP callable
   *
   * @return string The filtered CSS
   */
  protected function filterReferences($content, $callback, $limit = -1, &$count = 0) {
    $content = $this
      ->filterUrls($content, $callback, $limit, $count);
    $content = $this
      ->filterImports($content, $callback, $limit, $count, false);
    $content = $this
      ->filterIEFilters($content, $callback, $limit, $count);
    return $content;
  }

  /**
   * Filters all CSS url()'s through a callable.
   *
   * @param string  $content  The CSS
   * @param mixed   $callback A PHP callable
   * @param integer $limit    Limit the number of replacements
   * @param integer $count    Will be populated with the count
   *
   * @return string The filtered CSS
   */
  protected function filterUrls($content, $callback, $limit = -1, &$count = 0) {
    return preg_replace_callback('/url\\((["\']?)(?<url>.*?)(\\1)\\)/', $callback, $content, $limit, $count);
  }

  /**
   * Filters all CSS imports through a callable.
   *
   * @param string  $content    The CSS
   * @param mixed   $callback   A PHP callable
   * @param integer $limit      Limit the number of replacements
   * @param integer $count      Will be populated with the count
   * @param Boolean $includeUrl Whether to include url() in the pattern
   *
   * @return string The filtered CSS
   */
  protected function filterImports($content, $callback, $limit = -1, &$count = 0, $includeUrl = true) {
    $pattern = $includeUrl ? '/@import (?:url\\()?(\'|"|)(?<url>[^\'"\\)\\n\\r]*)\\1\\)?;?/' : '/@import (?!url\\()(\'|"|)(?<url>[^\'"\\)\\n\\r]*)\\1;?/';
    return preg_replace_callback($pattern, $callback, $content, $limit, $count);
  }

  /**
   * Filters all IE filters (AlphaImageLoader filter) through a callable.
   *
   * @param string  $content  The CSS
   * @param mixed   $callback A PHP callable
   * @param integer $limit    Limit the number of replacements
   * @param integer $count    Will be populated with the count
   *
   * @return string The filtered CSS
   */
  protected function filterIEFilters($content, $callback, $limit = -1, &$count = 0) {
    return preg_replace_callback('/src=(["\']?)(?<url>.*?)\\1/', $callback, $content, $limit, $count);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseCssFilter::filterIEFilters protected function Filters all IE filters (AlphaImageLoader filter) through a callable.
BaseCssFilter::filterImports protected function Filters all CSS imports through a callable.
BaseCssFilter::filterReferences protected function Filters all references -- url() and "@import" -- through a callable.
BaseCssFilter::filterUrls protected function Filters all CSS url()'s through a callable.
FilterInterface::filterDump public function Filters an asset just before it's dumped. 30
FilterInterface::filterLoad public function Filters an asset after it has been loaded. 27