From 7cc51d8596ffc9c74951ec9989722b20a5509068 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 5 Apr 2011 21:04:00 +0200 Subject: [PATCH] [FrameworkBundle] Fix resource inheritance in the template cache warmer --- .../CacheWarmer/TemplatePathsCacheWarmer.php | 15 +++++++++------ .../DependencyInjection/FrameworkExtension.php | 2 ++ .../Resources/config/templating.xml | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index fe0e971b5c86..22263594b4c6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Finder\Finder; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; +use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; /** * Computes the association between template names and their paths on the disk. @@ -24,20 +25,23 @@ class TemplatePathsCacheWarmer extends CacheWarmer { protected $kernel; - protected $rootDir; protected $parser; + protected $rootDir; + protected $locator; /** * Constructor. * * @param KernelInterface $kernel A KernelInterface instance * @param TemplateNameParser $parser A TemplateNameParser instance + * @param TemplateLocator $locator The template locator * @param string $rootDir The directory where global templates can be stored */ - public function __construct(KernelInterface $kernel, TemplateNameParser $parser, $rootDir) + public function __construct(KernelInterface $kernel, TemplateNameParser $parser, TemplateLocator $locator, $rootDir) { $this->kernel = $kernel; $this->parser = $parser; + $this->locator = $locator; $this->rootDir = $rootDir; } @@ -51,7 +55,6 @@ public function warmUp($cacheDir) $templates = array(); foreach ($this->kernel->getBundles() as $name => $bundle) { - $templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name); $templates += $this->findTemplatesIn($bundle->getPath().'/Resources/views', $name); } @@ -88,9 +91,9 @@ protected function findTemplatesIn($dir, $bundle = null) $template = $this->parser->parseFromFilename($file->getRelativePathname()); if (false !== $template) { if (null !== $bundle) { - $template->set('bundle', $bundle); - } - $templates[$template->getSignature()] = $file->getRealPath(); + $template->set('bundle', $bundle); + } + $templates[$template->getSignature()] = $this->locator->locate($template); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 0c438f7961a1..e8706b64a12b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -368,6 +368,8 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB if ($config['cache_warmer']) { $container->getDefinition('templating.cache_warmer.template_paths')->addTag('kernel.cache_warmer'); $container->setAlias('templating.locator', 'templating.locator.cached'); + } else { + $container->setAlias('templating.locator', 'templating.locator.uncached'); } $this->addClassesToCompile(array( diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml index 1be39f1d3cbb..c7a9f2920d84 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml @@ -25,7 +25,7 @@ - + %kernel.root_dir%/Resources @@ -39,6 +39,7 @@ + %kernel.root_dir%/Resources