[AsseticBundle] added local caching to the controller

This commit is contained in:
Kris Wallsmith 2011-02-16 08:23:07 -08:00 committed by Fabien Potencier
parent 42a68d9ca4
commit cd5b60359d
3 changed files with 18 additions and 2 deletions

View File

@ -11,7 +11,9 @@
namespace Symfony\Bundle\AsseticBundle\Controller;
use Assetic\Asset\AssetCache;
use Assetic\AssetManager;
use Assetic\Cache\CacheInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -26,12 +28,14 @@ class AsseticController
protected $request;
protected $response;
protected $am;
protected $cache;
public function __construct(Request $request, Response $response, AssetManager $am)
public function __construct(Request $request, Response $response, AssetManager $am, CacheInterface $cache)
{
$this->request = $request;
$this->response = $response;
$this->am = $am;
$this->cache = $cache;
}
public function render($name)
@ -40,7 +44,7 @@ class AsseticController
throw new NotFoundHttpException('Asset Not Found');
}
$asset = $this->am->get($name);
$asset = $this->getAsset($name);
// validate if-modified-since
if (null !== $lastModified = $asset->getLastModified()) {
@ -57,4 +61,9 @@ class AsseticController
return $this->response;
}
protected function getAsset($name)
{
return new AssetCache($this->am->get($name), $this->cache);
}
}

View File

@ -7,6 +7,8 @@
<parameters>
<parameter key="assetic.controller.class">Symfony\Bundle\AsseticBundle\Controller\AsseticController</parameter>
<parameter key="assetic.routing_loader.class">Symfony\Bundle\AsseticBundle\Routing\AsseticLoader</parameter>
<parameter key="assetic.cache.class">Assetic\Cache\FilesystemCache</parameter>
<parameter key="assetic.cache_dir">%kernel.cache_dir%/assetic</parameter>
</parameters>
<services>
@ -18,6 +20,10 @@
<argument type="service" id="request" />
<argument type="service" id="response" />
<argument type="service" id="assetic.asset_manager" />
<argument type="service" id="assetic.cache" />
</service>
<service id="assetic.cache" class="%assetic.cache.class%" public="false">
<argument>%assetic.cache_dir%</argument>
</service>
</services>
</container>

View File

@ -39,6 +39,7 @@ class AsseticExtensionTest extends \PHPUnit_Framework_TestCase
$this->container->register('twig', 'Twig_Environment');
$this->container->setParameter('kernel.debug', false);
$this->container->setParameter('kernel.root_dir', __DIR__);
$this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.bundles', array());
}