Source of file CssUtils.php
Size: 3,687 Bytes - Last Modified: 2013-06-02T00:13:43+02:00
/home/theseer/Downloads/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Util/CssUtils.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | <?php /* * This file is part of the Assetic package, an OpenSky project. * * (c) 2010-2013 OpenSky Project Inc * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Assetic\Util; /** * CSS Utils. * * @author Kris Wallsmith <kris.wallsmith@gmail.com> */ 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); } final private function __construct() { } } |