AsseticBundle\Service::writeAsset PHP Method

writeAsset() public method

Write $asset to public directory.
public writeAsset ( Assetic\Asset\AssetInterface $asset, Assetic\Factory\AssetFactory $factory )
$asset Assetic\Asset\AssetInterface Asset to write
$factory Assetic\Factory\AssetFactory The factory this asset was generated with
    public function writeAsset(AssetInterface $asset, Factory\AssetFactory $factory)
    {
        // We're not interested in saving assets on request
        if (!$this->configuration->getBuildOnRequest()) {
            return;
        }
        // Write asset on disk on every request
        if (!$this->configuration->getWriteIfChanged()) {
            $this->write($asset, $factory);
            return;
        }
        $target = $this->configuration->getWebPath($asset->getTargetPath());
        $created = is_file($target);
        $isChanged = $created && filemtime($target) < $factory->getLastModified($asset);
        // And long requested optimization
        if (!$created || $isChanged) {
            $this->write($asset, $factory);
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @param string $collectionName
  * @param array $options
  * @return string
  * @throws \AsseticBundle\Exception\InvalidArgumentException
  */
 public function __invoke($collectionName, array $options = array())
 {
     if (!$this->service->getAssetManager()->has($collectionName)) {
         throw new Exception\InvalidArgumentException('Collection "' . $collectionName . '" does not exist.');
     }
     $asset = $this->service->getAssetManager()->get($collectionName);
     $this->service->writeAsset($asset);
     return $this->setupAsset($asset, $options);
 }
All Usage Examples Of AsseticBundle\Service::writeAsset