abstract class CssUtils

CSS Utils.

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

Hierarchy

Expanded class hierarchy of CssUtils

2 files declare their use of CssUtils
BaseCssFilter.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/BaseCssFilter.php
SassFilter.php in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/Sass/SassFilter.php

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Util/CssUtils.php, line 19

Namespace

Assetic\Util
View source
abstract class CssUtils {
  const REGEX_URLS = '/url\\((["\']?)(?P<url>.*?)(\\1)\\)/';
  const REGEX_IMPORTS = '/@import (?:url\\()?(\'|"|)(?P<url>[^\'"\\)\\n\\r]*)\\1\\)?;?/';
  const REGEX_IMPORTS_NO_URLS = '/@import (?!url\\()(\'|"|)(?P<url>[^\'"\\)\\n\\r]*)\\1;?/';
  const REGEX_IE_FILTERS = '/src=(["\']?)(?P<url>.*?)\\1/';

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

  /**
   * Filters all CSS url()'s through a callable.
   *
   * @param string   $content  The CSS
   * @param callable $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
   */
  public static function filterUrls($content, $callback, $limit = -1, &$count = 0) {
    return preg_replace_callback(static::REGEX_URLS, $callback, $content, $limit, $count);
  }

  /**
   * Filters all CSS imports through a callable.
   *
   * @param string   $content    The CSS
   * @param callable $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
   */
  public static function filterImports($content, $callback, $limit = -1, &$count = 0, $includeUrl = true) {
    $pattern = $includeUrl ? static::REGEX_IMPORTS : static::REGEX_IMPORTS_NO_URLS;
    return preg_replace_callback($pattern, $callback, $content, $limit, $count);
  }

  /**
   * Filters all IE filters (AlphaImageLoader filter) through a callable.
   *
   * @param string   $content  The CSS
   * @param callable $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
   */
  public static function filterIEFilters($content, $callback, $limit = -1, &$count = 0) {
    return preg_replace_callback(static::REGEX_IE_FILTERS, $callback, $content, $limit, $count);
  }

  /**
   * Extracts all references from the supplied CSS content.
   *
   * @param string $content The CSS content
   *
   * @return array An array of unique URLs
   */
  public static function extractImports($content) {
    $imports = array();
    static::filterImports($content, function ($matches) use (&$imports) {
      $imports[] = $matches['url'];
    });
    return array_unique($imports);
  }
  private final function __construct() {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CssUtils::extractImports public static function Extracts all references from the supplied CSS content.
CssUtils::filterIEFilters public static function Filters all IE filters (AlphaImageLoader filter) through a callable.
CssUtils::filterImports public static function Filters all CSS imports through a callable.
CssUtils::filterReferences public static function Filters all references -- url() and "@import" -- through a callable.
CssUtils::filterUrls public static function Filters all CSS url()'s through a callable.
CssUtils::REGEX_IE_FILTERS constant
CssUtils::REGEX_IMPORTS constant 1
CssUtils::REGEX_IMPORTS_NO_URLS constant 1
CssUtils::REGEX_URLS constant
CssUtils::__construct final private function