AssetManager\Service\AssetCacheManager::setCache PHP 메소드

setCache() 공개 메소드

Set the cache (if any) on the asset, and return the new AssetCache.
public setCache ( string $path, Assetic\Asset\AssetInterface $asset ) : Assetic\Asset\AssetCache
$path string Path to asset
$asset Assetic\Asset\AssetInterface Assetic Asset Interface
리턴 Assetic\Asset\AssetCache
    public function setCache($path, AssetInterface $asset)
    {
        $provider = $this->getProvider($path);
        if (!$provider instanceof CacheInterface) {
            return $asset;
        }
        $assetCache = new AssetCache($asset, $provider);
        $assetCache->mimetype = $asset->mimetype;
        return $assetCache;
    }

Usage Example

 /**
  * @covers \AssetManager\Service\AssetCacheManager::setCache
  */
 public function testSetCacheNoProviderFound()
 {
     $serviceManager = new ServiceManager();
     $config = array('my/path' => array('cache' => 'Apc'));
     $mockAsset = $this->getMockBuilder('\\Assetic\\Asset\\FileAsset')->disableOriginalConstructor()->getMock();
     $mockAsset->mimetype = 'image/png';
     $assetManager = new AssetCacheManager($serviceManager, $config);
     $assetCache = $assetManager->setCache('not/defined', $mockAsset);
     $this->assertFalse($assetCache instanceof AssetCache);
 }