Skip to content

Commit

Permalink
[FrameworkBundle] Fix resource inheritance in the template cache warmer
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Apr 8, 2011
1 parent 9ceec87 commit 7cc51d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Expand Up @@ -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.
Expand All @@ -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;
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Expand Up @@ -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(
Expand Down
Expand Up @@ -25,7 +25,7 @@
<argument type="service" id="kernel" />
</service>

<service id="templating.locator" class="%templating.locator.class%" public="false">
<service id="templating.locator.uncached" class="%templating.locator.class%" public="false">
<argument type="service" id="file_locator" />
<argument>%kernel.root_dir%/Resources</argument>
</service>
Expand All @@ -39,6 +39,7 @@
<service id="templating.cache_warmer.template_paths" class="%templating.cache_warmer.template_paths.class%" public="false">
<argument type="service" id="kernel" />
<argument type="service" id="templating.name_parser" />
<argument type="service" id="templating.locator.uncached" />
<argument>%kernel.root_dir%/Resources</argument>
</service>

Expand Down

0 comments on commit 7cc51d8

Please sign in to comment.