Browse Source

[FrameworkBundle] added getLogicalName() method to TemplateReference

Martin Hason 14 năm trước cách đây
mục cha
commit
6c4801945e

+ 12 - 1
src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php

@@ -35,7 +35,7 @@ class TemplateReference extends BaseTemplateReference
      * Returns the path to the template
      *  - as a path when the template is not part of a bundle
      *  - as a resource when the template is part of a bundle
-     * 
+     *
      * @return string A path to the template or a resource
      */
     public function getPath()
@@ -46,4 +46,15 @@ class TemplateReference extends BaseTemplateReference
         return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    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;
+    }
+
 }

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

@@ -41,6 +41,8 @@ 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(), $name);
     }
 
     public function getLogicalNameToTemplateProvider()
@@ -82,7 +84,7 @@ class TemplateNameParserTest extends TestCase
     public function testParseFromFilename($file, $ref)
     {
         $template = $this->parser->parseFromFilename($file);
-        
+
         if ($ref === false) {
             $this->assertFalse($template);
         } else {