getWebPath() public method

public getWebPath ( $file = null )
Example #1
0
 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);
 }
Example #2
0
 /**
  * Write $asset to public directory.
  *
  * @param AssetInterface $asset     Asset to write
  */
 public function writeAsset(AssetInterface $asset)
 {
     // We're not interested in saving assets on request
     if (!$this->configuration->getBuildOnRequest()) {
         return;
     }
     // Write asset on disk in every request
     if (!$this->configuration->getWriteIfChanged()) {
         $this->write($asset);
     }
     $target = $this->configuration->getWebPath($asset->getTargetPath());
     $created = is_file($target);
     $isChanged = $created && filemtime($target) < $asset->getLastModified();
     // And long requested optimization
     if (!$created || $isChanged) {
         $this->write($asset);
     }
 }
Example #3
0
 public function initLoadedModules(array $loadedModules)
 {
     $moduleConfiguration = $this->configuration->getModules();
     foreach ($loadedModules as $moduleName => $module) {
         $moduleName = strtolower($moduleName);
         if (!isset($moduleConfiguration[$moduleName])) {
             continue;
         }
         $conf = (array) $moduleConfiguration[$moduleName];
         $factory = new Factory\AssetFactory($conf['root_path']);
         $factory->setAssetManager($this->getAssetManager());
         $factory->setFilterManager($this->getFilterManager());
         $factory->setDebug($this->configuration->isDebug());
         $collections = (array) $conf['collections'];
         foreach ($collections as $name => $options) {
             $assets = isset($options['assets']) ? $options['assets'] : array();
             $filters = isset($options['filters']) ? $options['filters'] : array();
             $options = isset($options['options']) ? $options['options'] : array();
             $options['output'] = isset($options['output']) ? $options['output'] : $name;
             $filters = $this->initFilters($filters);
             /** @var $asset \Assetic\Asset\AssetCollection */
             $asset = $factory->createAsset($assets, $filters, $options);
             # allow to move all files 1:1 to new directory
             # its particulary usefull when this assets are images.
             if (isset($options['move_raw']) && $options['move_raw']) {
                 foreach ($asset as $key => $value) {
                     $name = md5($value->getSourceRoot() . $value->getSourcePath());
                     $value->setTargetPath($value->getSourcePath());
                     $value = $this->cache($value);
                     $this->assetManager->set($name, $value);
                 }
             } else {
                 $asset = $this->cache($asset);
                 $this->assetManager->set($name, $asset);
             }
         }
         $writer = new AssetWriter($this->configuration->getWebPath());
         $writer->writeManagerAssets($this->assetManager);
     }
 }
 /**
  * @expectedException \RuntimeException
  */
 public function testGetWebPathFailure()
 {
     $this->object->getWebPath();
 }