ソースを参照

[FrameworkBundle] made CachedTemplateLocator fallback to the regular TemplateLocator if the template is not in the cache (to be able to use an absolute template)

Fabien Potencier 14 年 前
コミット
72cdb480ab

+ 2 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml

@@ -35,6 +35,8 @@
 
         <service id="templating.locator.cached" class="%templating.locator.cached.class%" public="false">
             <argument>%kernel.cache_dir%</argument>
+            <argument type="service" id="file_locator" />
+            <argument>%kernel.root_dir%</argument>
         </service>
 
         <service id="templating.cache_warmer.template_paths" class="%templating.cache_warmer.template_paths.class%" public="false">

+ 8 - 3
src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php

@@ -19,20 +19,25 @@ use Symfony\Component\Templating\TemplateReferenceInterface;
  *
  * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  */
-class CachedTemplateLocator implements FileLocatorInterface
+class CachedTemplateLocator extends TemplateLocator
 {
     protected $templates;
 
     /**
      * Constructor.
+     *
+     * @param string               $cacheDir The cache path
+     * @param FileLocatorInterface $locator  A FileLocatorInterface instance
+     * @param string               $path     A global fallback path
      */
-    public function __construct($cacheDir)
+    public function __construct($cacheDir, FileLocatorInterface $locator, $path)
     {
         if (!file_exists($cache = $cacheDir.'/templates.php')) {
             throw new \RuntimeException(sprintf('The template locator cache is not warmed up (%s).', $cache));
         }
 
         $this->templates = require $cache;
+        parent::__construct($locator, $path);
     }
 
     /**
@@ -51,7 +56,7 @@ class CachedTemplateLocator implements FileLocatorInterface
         $key = $template->getSignature();
 
         if (!isset($this->templates[$key])) {
-            throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', json_encode($template)));
+            return parent::locate($template, $currentPath, $first);
         }
 
         return $this->templates[$key];