You are here

public function CssOptimizer::rewriteFileURI in Flysystem 8

Same name and namespace in other branches
  1. 3.x src/Asset/CssOptimizer.php \Drupal\flysystem\Asset\CssOptimizer::rewriteFileURI()
  2. 2.0.x src/Asset/CssOptimizer.php \Drupal\flysystem\Asset\CssOptimizer::rewriteFileURI()
  3. 3.0.x src/Asset/CssOptimizer.php \Drupal\flysystem\Asset\CssOptimizer::rewriteFileURI()

Prefixes all paths within a CSS file for processFile().

Note: the only reason this method is public is so color.module can call it; it is not on the AssetOptimizerInterface, so future refactorings can make it protected.

Parameters

array $matches: An array of matches by a preg_replace_callback() call that scans for url() references in CSS files, except for external or absolute ones.

Return value

string The file path.

Overrides CssOptimizer::rewriteFileURI

File

src/Asset/CssOptimizer.php, line 17

Class

CssOptimizer
Changes Drupal\Core\Asset\CssOptimizer to not remove absolute URLs.

Namespace

Drupal\flysystem\Asset

Code

public function rewriteFileURI($matches) {

  // Prefix with base and remove '../' segments where possible.
  $path = $this->rewriteFileURIBasePath . $matches[1];
  $last = '';
  while ($path != $last) {
    $last = $path;
    $path = preg_replace('`(^|/)(?!\\.\\./)([^/]+)/\\.\\./`', '$1', $path);
  }

  // file_url_transform_relative() was removed here.
  return 'url(' . file_create_url($path) . ')';
}