Deployment\Preprocessor::expandCssImports PHP Method

expandCssImports() public method

Expands @import(file) in CSS.
public expandCssImports ( $content, $origFile ) : string
return string
    public function expandCssImports($content, $origFile)
    {
        $dir = dirname($origFile);
        return preg_replace_callback('#@import\\s+(?:url)?[(\'"]+(.+)[)\'"]+;#U', function ($m) use($dir) {
            $file = $dir . '/' . $m[1];
            if (!is_file($file)) {
                return $m[0];
            }
            $s = file_get_contents($file);
            $newDir = dirname($file);
            $s = $this->expandCssImports($s, $file);
            if ($newDir !== $dir) {
                $tmp = $dir . '/';
                if (substr($newDir, 0, strlen($tmp)) === $tmp) {
                    $s = preg_replace('#\\burl\\(["\']?(?=[.\\w])(?!\\w+:)#', '$0' . substr($newDir, strlen($tmp)) . '/', $s);
                } elseif (strpos($s, 'url(') !== FALSE) {
                    return $m[0];
                }
            }
            return $s;
        }, $content);
    }