Processes an asset.
AssetInterface $asset An asset:
AssetInterface|null May optionally return a replacement asset
Overrides WorkerInterface::process
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));
}