Skip to content

Commit 72cdb48

Browse files
committed
[FrameworkBundle] made CachedTemplateLocator fallback to the regular TemplateLocator if the template is not in the cache (to be able to use an absolute template)
1 parent fc372bc commit 72cdb48

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
<service id="templating.locator.cached" class="%templating.locator.cached.class%" public="false">
3737
<argument>%kernel.cache_dir%</argument>
38+
<argument type="service" id="file_locator" />
39+
<argument>%kernel.root_dir%</argument>
3840
</service>
3941

4042
<service id="templating.cache_warmer.template_paths" class="%templating.cache_warmer.template_paths.class%" public="false">

src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,25 @@
1919
*
2020
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2121
*/
22-
class CachedTemplateLocator implements FileLocatorInterface
22+
class CachedTemplateLocator extends TemplateLocator
2323
{
2424
protected $templates;
2525

2626
/**
2727
* Constructor.
28+
*
29+
* @param string $cacheDir The cache path
30+
* @param FileLocatorInterface $locator A FileLocatorInterface instance
31+
* @param string $path A global fallback path
2832
*/
29-
public function __construct($cacheDir)
33+
public function __construct($cacheDir, FileLocatorInterface $locator, $path)
3034
{
3135
if (!file_exists($cache = $cacheDir.'/templates.php')) {
3236
throw new \RuntimeException(sprintf('The template locator cache is not warmed up (%s).', $cache));
3337
}
3438

3539
$this->templates = require $cache;
40+
parent::__construct($locator, $path);
3641
}
3742

3843
/**
@@ -51,7 +56,7 @@ public function locate($template, $currentPath = null, $first = true)
5156
$key = $template->getSignature();
5257

5358
if (!isset($this->templates[$key])) {
54-
throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', json_encode($template)));
59+
return parent::locate($template, $currentPath, $first);
5560
}
5661

5762
return $this->templates[$key];

0 commit comments

Comments
 (0)