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 |
/** * @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); }
public function testWriteAssetIfNotUpdated() { $this->configuration->setBuildOnRequest(true); $this->configuration->setWriteIfChanged(true); $this->object->build(); $manager = $this->object->getAssetManager(); $assets = $manager->get('base_css')->all(); /** @var \Assetic\Asset\AssetInterface $asset */ $asset = $assets[0]; $asset->setTargetPath($manager->get('base_css')->getTargetPath()); $targetFile = $this->configuration->getWebPath($asset->getTargetPath()); if (is_file($targetFile)) { unlink($targetFile); } $this->assertFileNotExists($targetFile); $this->object->writeAsset($asset); $this->assertFileExists($targetFile); $sourceFile = $asset->getSourceRoot() . '/' . $asset->getSourcePath(); $targetMTime = filemtime($targetFile); sleep(2); $modifiedAsset = new FileAsset($sourceFile); $modifiedAsset->setTargetPath($targetFile); $this->object->writeAsset($modifiedAsset); clearstatcache(true, $targetFile); $targetMTimeNotModified = filemtime($targetFile); $this->assertLessThanOrEqual($targetMTime, $targetMTimeNotModified); }