/** * Create list all assets */ private function findAssetsInCollection(AssetInterface $asset, $collectionName) { if ($asset instanceof AssetCollectionInterface) { foreach ($asset->all() as $subAsset) { $this->findAssetsInCollection($subAsset, $collectionName); } } else { if (!in_array($asset, $this->collectionAssets[$collectionName])) { $this->collectionAssets[$collectionName][] = $asset; } } }
/** * Get the sha1 hash of an asset or asset collection * * @param AssetInterface $asset * @param AssetFactory $factory * @return string */ protected function getHash(AssetInterface $asset, AssetFactory $factory) { $hash = hash_init('sha1'); if ($asset instanceof AssetCollectionInterface) { foreach ($asset->all() as $i => $leaf) { $this->hashAsset($leaf, $hash); } } else { $this->hashAsset($asset, $hash); } return substr(hash_final($hash), 0, 7); }
/** * @param AssetInterface $asset * @return string */ protected function getCacheKey(AssetInterface $asset) { $cacheKey = ''; if ($asset instanceof AssetCollectionInterface) { foreach ($asset->all() as $childAsset) { $cacheKey .= $childAsset->getSourcePath(); $cacheKey .= $childAsset->getLastModified(); } } else { $cacheKey .= $asset->getSourcePath(); $cacheKey .= $asset->getLastModified(); } foreach ($asset->getFilters() as $filter) { if ($filter instanceof HashableInterface) { $cacheKey .= $filter->hash(); } else { $cacheKey .= serialize($filter); } } return md5($cacheKey); }
/** * Builds a compile filename for an asset with the * requested extension. * * @param \Assetic\Asset\AssetInterface $asset * @param string $extension * @return string */ public function getCompileFileName(AssetInterface $asset, $extension) { $cacheKey = ''; $assetName = ''; if ($asset instanceof AssetCollectionInterface) { switch ($extension) { case 'css': $assetName = 'styles'; break; case 'js': default: $assetName = 'scripts'; break; } foreach ($asset->all() as $actualAsset) { $cacheKey .= $this->getCacheKey($actualAsset); } } else { $assetName = $asset->getSlug(); $cacheKey .= $this->getCacheKey($asset); } if ($values = $asset->getValues()) { asort($values); $cacheKey .= serialize($values); } $lastModified = $asset->getLastModified(); return $assetName . '.' . md5($cacheKey) . '_' . $lastModified . ".{$extension}"; }