浏览代码

removed TemplateReferenceInterface::getSignature() (replaced by the existing getLogicalName() which already acts as a unique identifier)

Fabien Potencier 14 年之前
父节点
当前提交
5be0bafe7f

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php

@@ -46,7 +46,7 @@ class TemplatePathsCacheWarmer extends CacheWarmer
         $templates = array();
 
         foreach ($this->finder->findAllTemplates() as $template) {
-            $templates[$template->getSignature()] = $this->locator->locate($template);
+            $templates[$template->getLogicalName()] = $this->locator->locate($template);
         }
 
         $this->writeCacheFile($cacheDir.'/templates.php', sprintf('<?php return %s;', var_export($templates, true)));

+ 2 - 1
src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php

@@ -72,7 +72,8 @@ class CachedTemplateLocator extends TemplateLocator
      */
     protected function getCachedTemplatePath(TemplateReferenceInterface $template)
     {
-        $key = $template->getSignature();
+        $key = $template->getLogicalName();
+
         return isset($this->templates[$key]) ? $this->templates[$key] : null;
     }
 }

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php

@@ -54,7 +54,7 @@ class TemplateLocator implements FileLocatorInterface
             throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface.");
         }
 
-        $key = $template->getSignature();
+        $key = $template->getLogicalName();
 
         if (isset($this->cache[$key])) {
             return $this->cache[$key];

+ 6 - 10
src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php

@@ -23,11 +23,11 @@ class TemplateReference extends BaseTemplateReference
     public function __construct($bundle = null, $controller = null, $name = null, $format = null, $engine = null)
     {
         $this->parameters = array(
-            'bundle'        => $bundle,
-            'controller'    => $controller,
-            'name'          => $name,
-            'format'        => $format,
-            'engine'        => $engine,
+            'bundle'     => $bundle,
+            'controller' => $controller,
+            'name'       => $name,
+            'format'     => $format,
+            'engine'     => $engine,
         );
     }
 
@@ -51,10 +51,6 @@ class TemplateReference extends BaseTemplateReference
      */
     public function getLogicalName()
     {
-        $parts = sprintf('%s:%s:', $this->get('bundle'), $this->get('controller'));
-        $elements = sprintf('%s.%s.%s', $this->get('name'), $this->get('format'), $this->get('engine'));
-
-        return $parts . $elements;
+        return sprintf('%s:%s:%s.%s.%s', $this->get('bundle'), $this->get('controller'), $this->get('name'), $this->get('format'), $this->get('engine'));
     }
-
 }

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php

@@ -48,7 +48,7 @@ class TemplateNameParserTest extends TestCase
     {
         $template = $this->parser->parse($name);
 
-        $this->assertEquals($template->getSignature(), $ref->getSignature());
+        $this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
         $this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
         $this->assertEquals($template->getLogicalName(), $name);
     }
@@ -96,7 +96,7 @@ class TemplateNameParserTest extends TestCase
         if ($ref === false) {
             $this->assertFalse($template);
         } else {
-            $this->assertEquals($template->getSignature(), $ref->getSignature());
+            $this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
         }
     }
 

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

@@ -88,7 +88,7 @@ class FilesystemLoader implements \Twig_LoaderInterface
     {
         $tpl = $this->parser->parse($name);
 
-        if (isset($this->cache[$key = $tpl->getSignature()])) {
+        if (isset($this->cache[$key = $tpl->getLogicalName()])) {
             return $this->cache[$key];
         }
 

+ 1 - 1
src/Symfony/Component/Templating/Loader/CacheLoader.php

@@ -50,7 +50,7 @@ class CacheLoader extends Loader
      */
     public function load(TemplateReferenceInterface $template)
     {
-        $key = $template->getSignature();
+        $key = $template->getLogicalName();
         $dir = $this->dir.DIRECTORY_SEPARATOR.substr($key, 0, 2);
         $file = substr($key, 2).'.tpl';
         $path = $dir.DIRECTORY_SEPARATOR.$file;

+ 1 - 1
src/Symfony/Component/Templating/PhpEngine.php

@@ -488,7 +488,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess
     {
         $template = $this->parser->parse($name);
 
-        $key = $template->getSignature();
+        $key = $template->getLogicalName();
         if (isset($this->cache[$key])) {
             return $this->cache[$key];
         }

+ 6 - 14
src/Symfony/Component/Templating/TemplateReference.php

@@ -20,11 +20,11 @@ class TemplateReference implements TemplateReferenceInterface
 {
     protected $parameters;
 
-    public function  __construct($name = null, $engine = null)
+    public function __construct($name = null, $engine = null)
     {
         $this->parameters = array(
-            'name'      => $name,
-            'engine'    => $engine,
+            'name'   => $name,
+            'engine' => $engine,
         );
     }
 
@@ -33,16 +33,6 @@ class TemplateReference implements TemplateReferenceInterface
         return $this->getLogicalName();
     }
 
-    /**
-     * Returns the template signature
-     *
-     * @return string A UID for the template
-     */
-    public function getSignature()
-    {
-        return md5(serialize($this->parameters));
-    }
-
     /**
      * Sets a template parameter.
      *
@@ -105,7 +95,9 @@ class TemplateReference implements TemplateReferenceInterface
     }
 
     /**
-     * Returns the template name
+     * Returns the "logical" template name.
+     *
+     * The template name acts as a unique identifier for the template.
      *
      * @return string The template name
      */

+ 3 - 8
src/Symfony/Component/Templating/TemplateReferenceInterface.php

@@ -48,13 +48,6 @@ interface TemplateReferenceInterface
      */
     function get($name);
 
-    /**
-     * Returns the template signature
-     *
-     * @return string A UID for the template
-     */
-    function getSignature();
-
     /**
      * Returns the path to the template.
      *
@@ -65,7 +58,9 @@ interface TemplateReferenceInterface
     function getPath();
 
     /**
-     * Returns the template name
+     * Returns the "logical" template name.
+     *
+     * The template name acts as a unique identifier for the template.
      *
      * @return string The template name
      */

+ 3 - 3
tests/Symfony/Tests/Component/Templating/PhpEngineTest.php

@@ -153,13 +153,13 @@ class ProjectTemplateLoader extends Loader
     public function setTemplate($name, $content)
     {
         $template = new TemplateReference($name, 'php');
-        $this->templates[$template->getSignature()] = $content;
+        $this->templates[$template->getLogicalName()] = $content;
     }
 
     public function load(TemplateReferenceInterface $template)
     {
-        if (isset($this->templates[$template->getSignature()])) {
-            return new StringStorage($this->templates[$template->getSignature()]);
+        if (isset($this->templates[$template->getLogicalName()])) {
+            return new StringStorage($this->templates[$template->getLogicalName()]);
         }
 
         return false;

+ 1 - 1
tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php

@@ -35,7 +35,7 @@ class TemplateNameParserTest extends \PHPUnit_Framework_TestCase
     {
         $template = $this->parser->parse($name);
 
-        $this->assertEquals($template->getSignature(), $ref->getSignature());
+        $this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
         $this->assertEquals($template->getLogicalName(), $name);
     }