public function process(AssetInterface $asset, AssetFactory $factory) { $path = $asset->getTargetPath(); $ext = pathinfo($path, PATHINFO_EXTENSION); $lastModified = $factory->getLastModified($asset); if (null !== $lastModified) { $path = substr_replace($path, "{$lastModified}.{$ext}", -1 * strlen($ext)); $asset->setTargetPath($path); } }
protected function getHash(AssetInterface $asset, AssetFactory $factory) { $hash = hash_init('sha1'); hash_update($hash, $factory->getLastModified($asset)); if ($asset instanceof AssetCollectionInterface) { foreach ($asset as $i => $leaf) { $sourcePath = $leaf->getSourcePath(); hash_update($hash, $sourcePath ?: $i); } } return substr(hash_final($hash), 0, 7); }
/** * Combines asset file references of a single type to produce * a URL reference to the combined contents. * @param array $assets List of asset files. * @param string $localPath File extension, used for aesthetic purposes only. * @return string URL to contents. */ protected function prepareRequest(array $assets, $localPath = null) { if (substr($localPath, -1) != '/') { $localPath = $localPath . '/'; } $this->localPath = $localPath; $this->storagePath = storage_path('cms/combiner/assets'); list($assets, $extension) = $this->prepareAssets($assets); /* * Cache and process */ $cacheKey = $this->getCacheKey($assets); $cacheInfo = $this->useCache ? $this->getCache($cacheKey) : false; if (!$cacheInfo) { $this->setHashOnCombinerFilters($cacheKey); $combiner = $this->prepareCombiner($assets); if ($this->useDeepHashing) { $factory = new AssetFactory($this->localPath); $lastMod = $factory->getLastModified($combiner); } else { $lastMod = $combiner->getLastModified(); } $cacheInfo = ['version' => $cacheKey . '-' . $lastMod, 'etag' => $cacheKey, 'lastMod' => $lastMod, 'files' => $assets, 'path' => $this->localPath, 'extension' => $extension]; $this->putCache($cacheKey, $cacheInfo); } return $this->getCombinedUrl($cacheInfo['version']); }
/** * Write collection in web folder * * @param Assetic\Factory\AssetFactory $assetFactory * @param string $file */ protected function writeAssets($assetFactory, $file, $web, $tragetFile) { if (true === $this->lastModifedHandler($assetFactory->getLastModified(), $file, $web . $tragetFile)) { $writer = new AssetWriter($web); $writer->writeAsset($assetFactory); } }