public function CacheBustingWorker::process

Processes an asset.

Parameters

AssetInterface $asset An asset:

Return value

AssetInterface|null May optionally return a replacement asset

Overrides WorkerInterface::process

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Factory/Worker/CacheBustingWorker.php, line 34

Class

CacheBustingWorker
Adds cache busting code

Namespace

Assetic\Factory\Worker

Code

public function process(AssetInterface $asset) {
  if (!($path = $asset
    ->getTargetPath())) {

    // no path to work with
    return;
  }
  if (!($search = pathinfo($path, PATHINFO_EXTENSION))) {

    // nothing to replace
    return;
  }
  $replace = $this->separator . $this
    ->getHash($asset) . '.' . $search;
  if (preg_match('/' . preg_quote($replace, '/') . '$/', $path)) {

    // already replaced
    return;
  }
  $asset
    ->setTargetPath(preg_replace('/\\.' . preg_quote($search, '/') . '$/', $replace, $path));
}