/** * Invoke filter * @param string code * @param WebLoader loader * @param string file * @return string */ public function __invoke($code, WebLoader $loader, $file = null) { // thanks to kravco $regexp = '~ (?<![a-z]) url\\( ## url( \\s* ## optional whitespace ([\'"])? ## optional single/double quote ( (?: (?:\\\\.)+ ## escape sequences | [^\'"\\\\,()\\s]+ ## safe characters | (?(1) (?!\\1)[\'"\\\\,() \\t] ## allowed special characters | ^ ## (none, if not quoted) ) )* ## (greedy match) ) (?(1)\\1) ## optional single/double quote \\s* ## optional whitespace \\) ## ) ~xs'; return preg_replace_callback($regexp, function ($matches) use($loader, $file) { return "url('" . CssUrlsFilter::absolutizeUrl($matches[2], $matches[1], $file, $loader->sourcePath) . "')"; }, $code); }
function m($matches, $file, $sourcePath) { // NDebug::dump($file); NDebug::dump($matches); // NDebug::dump($sourcePath); return "url('" . CssUrlsFilter::absolutizeUrl($matches[2], $matches[1], $file, $sourcePath) . "')"; }