Ver Fonte

[TwigBundle] Normalize names of templates and enable cache found templates file names

Sergey Linnik há 14 anos atrás
pai
commit
22aba900d4

+ 6 - 6
src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php

@@ -52,15 +52,15 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
 
     protected function findTemplate($name)
     {
-        list($tpl, $options) = $this->nameParser->parse($name);
-
         // normalize name
-        $tpl = preg_replace('#/{2,}#', '/', strtr($tpl, '\\', '/'));
+        $name = str_replace(':/' , ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')));
 
-        if (isset($this->cache[$tpl])) {
-            return $this->cache[$tpl];
+        if (isset($this->cache[$name])) {
+            return $this->cache[$name];
         }
 
+        list($tpl, $options) = $this->nameParser->parse($name);
+
         $this->validateName($tpl);
         $this->validateName($options['bundle']);
         $this->validateName($options['controller']);
@@ -80,7 +80,7 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
                     $this->logger->info(sprintf('Loaded template file "%s"', $file));
                 }
 
-                return $file;
+                return $this->cache[$name] = $file;
             }
 
             if (null !== $this->logger) {