コード例 #1
0
 public function process(AssetInterface $asset)
 {
     $hash = hash_init('sha1');
     switch ($this->strategy) {
         case self::STRATEGY_MODIFICATION:
             hash_update($hash, $asset->getLastModified());
             break;
         case self::STRATEGY_CONTENT:
             hash_update($hash, $asset->dump());
             break;
     }
     foreach ($asset as $i => $leaf) {
         if ($sourcePath = $leaf->getSourcePath()) {
             hash_update($hash, $sourcePath);
         } else {
             hash_update($hash, $i);
         }
     }
     $hash = substr(hash_final($hash), 0, 7);
     $url = $asset->getTargetPath();
     $oldExt = pathinfo($url, PATHINFO_EXTENSION);
     $newExt = '-' . $hash . '.' . $oldExt;
     if (!$oldExt || 0 < preg_match('/' . preg_quote($newExt, '/') . '$/', $url)) {
         return;
     }
     $asset->setTargetPath(substr($url, 0, (strlen($oldExt) + 1) * -1) . $newExt);
 }
コード例 #2
0
 public function process(AssetInterface $asset, AssetFactory $factory)
 {
     $targetUrl = $asset->getTargetPath();
     if ($targetUrl && '/' != $targetUrl[0] && 0 !== strpos($targetUrl, '_controller/')) {
         $asset->setTargetPath('_controller/' . $targetUrl);
     }
     return $asset;
 }
コード例 #3
0
 public function process(AssetInterface $asset, AssetFactory $factory)
 {
     $path = $asset->getTargetPath();
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     $lastModified = $asset->getLastModified();
     if (null !== $lastModified) {
         $path = substr_replace($path, "{$lastModified}.{$ext}", -1 * strlen($ext));
         $asset->setTargetPath($path);
     }
 }
コード例 #4
0
 /**
  * Processes an asset.
  *
  * @param AssetInterface $asset An asset
  *
  * @return AssetInterface|null May optionally return a replacement asset
  */
 public function process(AssetInterface $asset)
 {
     $path = $asset->getTargetPath();
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     $revision = $this->getRevision();
     if (null !== $revision) {
         $path = substr_replace($path, "{$revision}.{$ext}", -1 * strlen($ext));
         $asset->setTargetPath($path);
     }
 }
コード例 #5
0
 public function filterDump(AssetInterface $asset)
 {
     $originalTargetPath = $asset->getTargetPath();
     $targetPath = str_replace('_controller/', '', $originalTargetPath);
     $asset->setTargetPath($targetPath);
     try {
         parent::filterDump($asset);
     } catch (\Exception $e) {
         if ($targetPath === $asset->getTargetPath()) {
             $asset->setTargetPath($originalTargetPath);
         }
         throw $e;
     }
     if ($targetPath === $asset->getTargetPath()) {
         $asset->setTargetPath($originalTargetPath);
     }
 }
コード例 #6
0
ファイル: LazyAsset.php プロジェクト: puli/assetic-extension
 private function createInnerAsset()
 {
     if ($this->innerAsset) {
         throw new RuntimeException('The inner asset must be created only once.');
     }
     $this->innerAsset = $this->factory->parseInputWithFixedValues($this->input, $this->currentDir, $this->roots, $this->vars, $this->values);
     foreach ($this->filters as $filter) {
         $this->innerAsset->ensureFilter($filter);
     }
     if (null !== $this->content) {
         $this->innerAsset->setContent($this->content);
     }
     if (null !== $this->targetPath) {
         $this->innerAsset->setTargetPath($this->targetPath);
     }
     // GC
     $this->factory = null;
     $this->input = null;
     $this->currentDir = null;
     $this->roots = null;
     $this->content = null;
     $this->targetPath = null;
 }
コード例 #7
0
 /**
  * Sets the URL for the current asset.
  *
  * @param string $targetPath A web URL where the asset will be dumped
  */
 public function setTargetPath($targetPath)
 {
     $this->asset->setTargetPath($targetPath);
 }