From cd5b60359d3af704c0e051ceb0370f53731c0962 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 16 Feb 2011 08:23:07 -0800 Subject: [PATCH] [AsseticBundle] added local caching to the controller --- .../AsseticBundle/Controller/AsseticController.php | 13 +++++++++++-- .../AsseticBundle/Resources/config/controller.xml | 6 ++++++ .../DependencyInjection/AsseticExtensionTest.php | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php b/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php index b35408944ad4..ea1232f0c3a5 100644 --- a/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php +++ b/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php @@ -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 @@ public function render($name) 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 @@ public function render($name) return $this->response; } + + protected function getAsset($name) + { + return new AssetCache($this->am->get($name), $this->cache); + } } diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml index efc2fa8463fc..3a10b539cc9b 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml @@ -7,6 +7,8 @@ Symfony\Bundle\AsseticBundle\Controller\AsseticController Symfony\Bundle\AsseticBundle\Routing\AsseticLoader + Assetic\Cache\FilesystemCache + %kernel.cache_dir%/assetic @@ -18,6 +20,10 @@ + + + + %assetic.cache_dir% diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php index bc6281dc1254..faad33340edf 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php @@ -39,6 +39,7 @@ protected function setUp() $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()); }