Same name in other branches
  1. 6.0.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::loadNestedFile()
  2. 8.x-3.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::loadNestedFile()
  3. 8.x-4.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::loadNestedFile()

Loads stylesheets recursively and returns contents with corrected paths.

This function is used for recursive loading of stylesheets and returns the stylesheet content with all url() paths corrected.

Parameters

array $matches: An array of matches files to load.

Return value

string The contents of the CSS file at $matches[1], with corrected paths.

See also

\Drupal\Core\Asset\CssOptimizer::loadFile()

File

advagg_css_minify/src/Asset/CssMinifier.php, line 188

Class

CssMinifier
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_css_minify\Asset

Code

protected function loadNestedFile(array $matches) {
    $filename = $matches[1];
    // Load the imported stylesheet and replace @import commands in there as
    // well.
    $file = $this->loadFile($filename);
    // Determine the file's directory.
    $directory = dirname($filename);
    // If the file is in the current directory, make sure '.' doesn't appear in
    // the url() path.
    $directory = $directory == '.' ? '' : $directory . '/';
    // Alter all internal url() paths. Leave external paths alone. We don't need
    // to normalize absolute paths here because that will be done later. Also
    // ignore SVG paths (# or %23).
    return preg_replace('/url\\(\\s*([\'"]?)(?![a-z]+:|\\/+|\\#|\\%23+)([^\'")]+)([\'"]?)\\s*\\)/i', 'url(\\1' . $directory . '\\2\\3)', $file);
}