Преглед изворни кода

[FrameworkBundle] Fix resource inheritance in the template cache warmer

Victor Berchet пре 14 година
родитељ
комит
7cc51d8596

+ 9 - 6
src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php

@@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
 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 @@ use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
 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 @@ class TemplatePathsCacheWarmer extends CacheWarmer
         $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 @@ class TemplatePathsCacheWarmer extends CacheWarmer
                 $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);
                 }
             }
         }

+ 2 - 0
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

@@ -368,6 +368,8 @@ class FrameworkExtension extends Extension
         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(

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

@@ -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>
@@ -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>