diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index c82b44497f..4ed868e440 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -14,8 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Finder\Finder; -use Symfony\Component\Config\FileLocatorInterface; -use Symfony\Bundle\FrameworkBundle\Templating\Template; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; /** @@ -25,7 +23,8 @@ use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; */ class TemplatePathsCacheWarmer extends CacheWarmer { - protected $locator; + const TEMPLATES_PATH_IN_BUNDLE = '/Resources/views'; + protected $kernel; protected $rootDir; protected $parser; @@ -34,14 +33,12 @@ class TemplatePathsCacheWarmer extends CacheWarmer * Constructor. * * @param KernelInterface $kernel A KernelInterface instance - * @param FileLocatorInterface $locator A FileLocatorInterface instance * @param TemplateNameParser $parser A TemplateNameParser instance * @param string $rootDir The directory where global templates can be stored */ - public function __construct(KernelInterface $kernel, FileLocatorInterface $locator, TemplateNameParser $parser, $rootDir) + public function __construct(KernelInterface $kernel, TemplateNameParser $parser, $rootDir) { $this->kernel = $kernel; - $this->locator = $locator; $this->parser = $parser; $this->rootDir = $rootDir; } @@ -52,8 +49,14 @@ class TemplatePathsCacheWarmer extends CacheWarmer * @param string $cacheDir The cache directory */ public function warmUp($cacheDir) - { - $templates = $this->computeTemplatePaths(); + { + $templates = array(); + + foreach ($this->kernel->getBundles() as $name => $bundle) { + $templates += $this->findTemplatesIn($bundle->getPath().self::TEMPLATES_PATH_IN_BUNDLE, $name); + } + + $templates += $this->findTemplatesIn($this->rootDir); $this->writeCacheFile($cacheDir.'/templates.php', sprintf('kernel->getBundles() as $name => $bundle) { - if (!is_dir($dir = $bundle->getPath().$prefix)) { - continue; - } + if (is_dir($dir)) { $finder = new Finder(); foreach ($finder->files()->followLinks()->in($dir) as $file) { $template = $this->parser->parseFromFilename($file->getRelativePathname()); if (false !== $template) { - $template->set('bundle', $name); - $templates[$template->getSignature()] = $this->locator->locate($template->getPath(), $this->rootDir); - } - } - } - - if (is_dir($this->rootDir)) { - $finder = new Finder(); - foreach ($finder->files()->followLinks()->in($this->rootDir) as $file) { - $template = $this->parser->parseFromFilename($file->getRelativePathname()); - if (false !== $template) { + if (null !== $bundle) { + $template->set('bundle', $bundle); + } $templates[$template->getSignature()] = $file->getRealPath(); } } } - return $templates; + return $templates; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml index 39fa79df9b..754a96faa3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml @@ -41,7 +41,6 @@ - %kernel.root_dir%/views