From f6c12bd6de732d0c1b15a084e3b8e180519277e2 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 4 Sep 2013 14:01:22 +0200 Subject: [PATCH] [Templating] fix logic regarding template references and many phpdocs --- .../Bridge/Twig/Tests/TwigEngineTest.php | 22 ++++++++ src/Symfony/Bridge/Twig/TwigEngine.php | 41 +++++++-------- src/Symfony/Bridge/Twig/composer.json | 16 +++--- .../Templating/DelegatingEngine.php | 50 ++++++++----------- .../Templating/EngineInterface.php | 2 + .../Templating/Loader/FilesystemLoader.php | 13 +---- .../Templating/Loader/TemplateLocator.php | 2 +- .../FrameworkBundle/Templating/PhpEngine.php | 10 +--- .../Templating/TemplateFilenameParser.php | 8 ++- .../Templating/TimedPhpEngine.php | 2 - .../Tests/Templating/DelegatingEngineTest.php | 11 +++- .../TwigBundle/Loader/FilesystemLoader.php | 15 +++--- .../Tests/Loader/FilesystemLoaderTest.php | 6 +-- src/Symfony/Bundle/TwigBundle/TwigEngine.php | 19 ++----- .../Component/Templating/DelegatingEngine.php | 2 +- .../Component/Templating/EngineInterface.php | 12 +++-- .../Component/Templating/PhpEngine.php | 22 ++------ .../Templating/StreamingEngineInterface.php | 4 +- .../Templating/TemplateNameParser.php | 6 +-- .../TemplateNameParserInterface.php | 2 +- .../Templating/TemplateReference.php | 36 +++---------- .../Templating/TemplateReferenceInterface.php | 15 +++++- 22 files changed, 142 insertions(+), 174 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php b/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php index 98a60f68b7..e7047c354d 100644 --- a/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php +++ b/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Twig\Tests; use Symfony\Bridge\Twig\TwigEngine; +use Symfony\Component\Templating\TemplateReference; class TwigEngineTest extends \PHPUnit_Framework_TestCase { @@ -27,6 +28,7 @@ class TwigEngineTest extends \PHPUnit_Framework_TestCase $engine = $this->getTwig(); $this->assertFalse($engine->exists('foobar')); + $this->assertFalse($engine->exists(new TemplateReference('foorbar'))); } public function testExistsWithTemplateWithSyntaxErrors() @@ -34,6 +36,7 @@ class TwigEngineTest extends \PHPUnit_Framework_TestCase $engine = $this->getTwig(); $this->assertTrue($engine->exists('error')); + $this->assertTrue($engine->exists(new TemplateReference('error'))); } public function testExists() @@ -41,6 +44,25 @@ class TwigEngineTest extends \PHPUnit_Framework_TestCase $engine = $this->getTwig(); $this->assertTrue($engine->exists('index')); + $this->assertTrue($engine->exists(new TemplateReference('index'))); + } + + public function testRender() + { + $engine = $this->getTwig(); + + $this->assertSame('foo', $engine->render('index')); + $this->assertSame('foo', $engine->render(new TemplateReference('index'))); + } + + /** + * @expectedException \Twig_Error_Syntax + */ + public function testRenderWithError() + { + $engine = $this->getTwig(); + + $engine->render(new TemplateReference('error')); } protected function getTwig() diff --git a/src/Symfony/Bridge/Twig/TwigEngine.php b/src/Symfony/Bridge/Twig/TwigEngine.php index 41e15bacaa..3e3257e7fa 100644 --- a/src/Symfony/Bridge/Twig/TwigEngine.php +++ b/src/Symfony/Bridge/Twig/TwigEngine.php @@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig; use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\StreamingEngineInterface; use Symfony\Component\Templating\TemplateNameParserInterface; +use Symfony\Component\Templating\TemplateReferenceInterface; /** * This engine knows how to render Twig templates. @@ -38,15 +39,11 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface } /** - * Renders a template. + * {@inheritdoc} * - * @param mixed $name A template name - * @param array $parameters An array of parameters to pass to the template + * It also supports \Twig_Template as name parameter. * - * @return string The evaluated template as a string - * - * @throws \InvalidArgumentException if the template does not exist - * @throws \RuntimeException if the template cannot be rendered + * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template */ public function render($name, array $parameters = array()) { @@ -54,12 +51,11 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface } /** - * Streams a template. + * {@inheritdoc} * - * @param mixed $name A template name or a TemplateReferenceInterface instance - * @param array $parameters An array of parameters to pass to the template + * It also supports \Twig_Template as name parameter. * - * @throws \RuntimeException if the template cannot be rendered + * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template */ public function stream($name, array $parameters = array()) { @@ -67,11 +63,9 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface } /** - * Returns true if the template exists. + * {@inheritdoc} * - * @param mixed $name A template name - * - * @return Boolean true if the template exists, false otherwise + * It also supports \Twig_Template as name parameter. */ public function exists($name) { @@ -82,11 +76,13 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface $loader = $this->environment->getLoader(); if ($loader instanceof \Twig_ExistsLoaderInterface) { - return $loader->exists($name); + return $loader->exists((string) $name); } try { - $loader->getSource($name); + // cast possible TemplateReferenceInterface to string because the + // EngineInterface supports them but Twig_LoaderInterface does not + $loader->getSource((string) $name); } catch (\Twig_Error_Loader $e) { return false; } @@ -95,11 +91,9 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface } /** - * Returns true if this class is able to render the given template. + * {@inheritdoc} * - * @param string $name A template name - * - * @return Boolean True if this class supports the given resource, false otherwise + * It also supports \Twig_Template as name parameter. */ public function supports($name) { @@ -115,7 +109,8 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface /** * Loads the given template. * - * @param mixed $name A template name or an instance of Twig_Template + * @param string|TemplateReferenceInterface|\Twig_Template $name A template name or an instance of + * TemplateReferenceInterface or \Twig_Template * * @return \Twig_TemplateInterface A \Twig_TemplateInterface instance * @@ -128,7 +123,7 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface } try { - return $this->environment->loadTemplate($name); + return $this->environment->loadTemplate((string) $name); } catch (\Twig_Error_Loader $e) { throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e); } diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 5797586731..0eb9eeec6f 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -30,14 +30,14 @@ "symfony/stopwatch": "~2.2" }, "suggest": { - "symfony/form": "", - "symfony/http-kernel": "", - "symfony/routing": "", - "symfony/templating": "", - "symfony/translation": "", - "symfony/yaml": "", - "symfony/security": "", - "symfony/stopwatch": "" + "symfony/form": "For using the FormExtension", + "symfony/http-kernel": "For using the HttpKernelExtension", + "symfony/routing": "For using the RoutingExtension", + "symfony/templating": "For using the TwigEngine", + "symfony/translation": "For using the TranslationExtension", + "symfony/yaml": "For using the YamlExtension", + "symfony/security": "For using the SecurityExtension", + "symfony/stopwatch": "For using the StopwatchExtension" }, "autoload": { "psr-0": { "Symfony\\Bridge\\Twig\\": "" } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php b/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php index 7d9f672ef0..ab0614f2b8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php @@ -40,50 +40,42 @@ class DelegatingEngine extends BaseDelegatingEngine implements EngineInterface /** * {@inheritdoc} */ - public function supports($name) + public function getEngine($name) { - foreach ($this->engines as $i => $engine) { - if (is_string($engine)) { - $engine = $this->engines[$i] = $this->container->get($engine); - } + $this->resolveEngines(); - if ($engine->supports($name)) { - return true; - } - } - - return false; + return parent::getEngine($name); } /** * {@inheritdoc} */ - public function getEngine($name) + public function renderResponse($view, array $parameters = array(), Response $response = null) { - foreach ($this->engines as $i => $engine) { - if (is_string($engine)) { - $engine = $this->engines[$i] = $this->container->get($engine); - } + $engine = $this->getEngine($view); - if ($engine->supports($name)) { - return $engine; - } + if ($engine instanceof EngineInterface) { + return $engine->renderResponse($view, $parameters, $response); } - throw new \RuntimeException(sprintf('No engine is able to work with the template "%s".', $name)); + if (null === $response) { + $response = new Response(); + } + + $response->setContent($engine->render($view, $parameters)); + + return $response; } /** - * Renders a view and returns a Response. - * - * @param string $view The view name - * @param array $parameters An array of parameters to pass to the view - * @param Response $response A Response instance - * - * @return Response A Response instance + * Resolved engine ids to their real engine instances from the container. */ - public function renderResponse($view, array $parameters = array(), Response $response = null) + private function resolveEngines() { - return $this->getEngine($view)->renderResponse($view, $parameters, $response); + foreach ($this->engines as $i => $engine) { + if (is_string($engine)) { + $this->engines[$i] = $this->container->get($engine); + } + } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/EngineInterface.php b/src/Symfony/Bundle/FrameworkBundle/Templating/EngineInterface.php index edc087e867..dcf5897517 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/EngineInterface.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/EngineInterface.php @@ -29,6 +29,8 @@ interface EngineInterface extends BaseEngineInterface * @param Response $response A Response instance * * @return Response A Response instance + * + * @throws \RuntimeException if the template cannot be rendered */ public function renderResponse($view, array $parameters = array(), Response $response = null); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php index ac917e7908..4f6cffc103 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/FilesystemLoader.php @@ -36,11 +36,7 @@ class FilesystemLoader implements LoaderInterface } /** - * Loads a template. - * - * @param TemplateReferenceInterface $template A template - * - * @return FileStorage|Boolean false if the template cannot be loaded, a Storage instance otherwise + * {@inheritdoc} */ public function load(TemplateReferenceInterface $template) { @@ -54,12 +50,7 @@ class FilesystemLoader implements LoaderInterface } /** - * Returns true if the template is still fresh. - * - * @param TemplateReferenceInterface $template The template name as an array - * @param integer $time The last modification time of the cached template (timestamp) - * - * @return Boolean + * {@inheritdoc} */ public function isFresh(TemplateReferenceInterface $template, $time) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index 0ff6b8cbb7..e9500de27e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -66,7 +66,7 @@ class TemplateLocator implements FileLocatorInterface public function locate($template, $currentPath = null, $first = true) { if (!$template instanceof TemplateReferenceInterface) { - throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface."); + throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.'); } $key = $this->getCacheKey($template); diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php b/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php index a93098eb84..41382f769c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php @@ -46,7 +46,7 @@ class PhpEngine extends BasePhpEngine implements EngineInterface } /** - * @throws \InvalidArgumentException When the helper is not defined + * {@inheritdoc} */ public function get($name) { @@ -71,13 +71,7 @@ class PhpEngine extends BasePhpEngine implements EngineInterface } /** - * Renders a view and returns a Response. - * - * @param string $view The view name - * @param array $parameters An array of parameters to pass to the view - * @param Response $response A Response instance - * - * @return Response A Response instance + * {@inheritdoc} */ public function renderResponse($view, array $parameters = array(), Response $response = null) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php index befb3e8f85..bf41ca81f1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php @@ -24,9 +24,13 @@ class TemplateFilenameParser implements TemplateNameParserInterface /** * {@inheritdoc} */ - public function parse($file) + public function parse($name) { - $parts = explode('/', strtr($file, '\\', '/')); + if ($name instanceof TemplateReferenceInterface) { + return $name; + } + + $parts = explode('/', strtr($name, '\\', '/')); $elements = explode('.', array_pop($parts)); if (3 > count($elements)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TimedPhpEngine.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TimedPhpEngine.php index cdbdc6f2bb..cd2a928a89 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TimedPhpEngine.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TimedPhpEngine.php @@ -11,8 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Templating; -use Symfony\Bundle\FrameworkBundle\Templating\PhpEngine; -use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables; use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Templating\Loader\LoaderInterface; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php index 67b17c0660..f3a46be70c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php @@ -58,7 +58,7 @@ class DelegatingEngineTest extends \PHPUnit_Framework_TestCase $delegatingEngine->getEngine('template.php', array('foo' => 'bar')); } - public function testRenderResponse() + public function testRenderResponseWithFrameworkEngine() { $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); $engine = $this->getFrameworkEngineMock('template.php', true); @@ -73,6 +73,15 @@ class DelegatingEngineTest extends \PHPUnit_Framework_TestCase $this->assertSame($response, $delegatingEngine->renderResponse('template.php', array('foo' => 'bar'))); } + public function testRenderResponseWithTemplatingEngine() + { + $engine = $this->getEngineMock('template.php', true); + $container = $this->getContainerMock(array('engine' => $engine)); + $delegatingEngine = new DelegatingEngine($container, array('engine')); + + $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $delegatingEngine->renderResponse('template.php', array('foo' => 'bar'))); + } + private function getEngineMock($template, $supports) { $engine = $this->getMock('Symfony\Component\Templating\EngineInterface'); diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index f76b5d0b8e..0fe62fbcf4 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -11,13 +11,13 @@ namespace Symfony\Bundle\TwigBundle\Loader; -use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Config\FileLocatorInterface; +use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Templating\TemplateReferenceInterface; /** * FilesystemLoader extends the default Twig filesystem loader - * to work with the Symfony2 paths. + * to work with the Symfony2 paths and template references. * * @author Fabien Potencier */ @@ -38,21 +38,22 @@ class FilesystemLoader extends \Twig_Loader_Filesystem $this->locator = $locator; $this->parser = $parser; - $this->cache = array(); } /** * {@inheritdoc} + * + * The name parameter might also be a TemplateReferenceInterface. */ - public function exists($template) + public function exists($name) { - if (parent::exists($template)) { + if (parent::exists((string) $name)) { return true; } // same logic as findTemplate below for the fallback try { - $this->cache[(string) $template] = $this->locator->locate($this->parser->parse($template)); + $this->cache[(string) $name] = $this->locator->locate($this->parser->parse($name)); } catch (\Exception $e) { return false; } @@ -84,7 +85,7 @@ class FilesystemLoader extends \Twig_Loader_Filesystem $file = null; $previous = null; try { - $file = parent::findTemplate($template); + $file = parent::findTemplate($logicalName); } catch (\Twig_Error_Loader $e) { $previous = $e; diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php index 230fd92e40..cd0329224a 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php @@ -11,11 +11,9 @@ namespace Symfony\Bundle\TwigBundle\Tests\Loader; -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader; -use Symfony\Component\Config\FileLocatorInterface; use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; -use Symfony\Component\Templating\TemplateNameParserInterface; +use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader; +use Symfony\Bundle\TwigBundle\Tests\TestCase; class FilesystemLoaderTest extends TestCase { diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index fbb8602992..f6ffbb4d61 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -62,16 +62,7 @@ class TwigEngine extends BaseEngine implements EngineInterface } /** - * Renders a template. - * - * @param mixed $name A template name - * @param array $parameters An array of parameters to pass to the template - * - * @return string The evaluated template as a string - * - * @throws \InvalidArgumentException if the template does not exist - * @throws \RuntimeException if the template cannot be rendered - * @throws \Twig_Error + * {@inheritdoc} */ public function render($name, array $parameters = array()) { @@ -91,13 +82,9 @@ class TwigEngine extends BaseEngine implements EngineInterface } /** - * Renders a view and returns a Response. + * {@inheritdoc} * - * @param string $view The view name - * @param array $parameters An array of parameters to pass to the view - * @param Response $response A Response instance - * - * @return Response A Response instance + * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template */ public function renderResponse($view, array $parameters = array(), Response $response = null) { diff --git a/src/Symfony/Component/Templating/DelegatingEngine.php b/src/Symfony/Component/Templating/DelegatingEngine.php index 4688114a7b..ce7e833b55 100644 --- a/src/Symfony/Component/Templating/DelegatingEngine.php +++ b/src/Symfony/Component/Templating/DelegatingEngine.php @@ -106,7 +106,7 @@ class DelegatingEngine implements EngineInterface, StreamingEngineInterface /** * Get an engine able to render the given template. * - * @param mixed $name A template name or a TemplateReferenceInterface instance + * @param string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance * * @return EngineInterface The engine * diff --git a/src/Symfony/Component/Templating/EngineInterface.php b/src/Symfony/Component/Templating/EngineInterface.php index dfa9c55efa..a7291bfa81 100644 --- a/src/Symfony/Component/Templating/EngineInterface.php +++ b/src/Symfony/Component/Templating/EngineInterface.php @@ -23,7 +23,7 @@ namespace Symfony\Component\Templating; * TemplateReferenceInterface, a TemplateNameParserInterface should be used to * convert the name to a TemplateReferenceInterface instance. * - * Each template loader use the logical template name to look for + * Each template loader uses the logical template name to look for * the template. * * @author Fabien Potencier @@ -35,8 +35,8 @@ interface EngineInterface /** * Renders a template. * - * @param mixed $name A template name or a TemplateReferenceInterface instance - * @param array $parameters An array of parameters to pass to the template + * @param string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance + * @param array $parameters An array of parameters to pass to the template * * @return string The evaluated template as a string * @@ -49,10 +49,12 @@ interface EngineInterface /** * Returns true if the template exists. * - * @param mixed $name A template name or a TemplateReferenceInterface instance + * @param string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance * * @return Boolean true if the template exists, false otherwise * + * @throws \RuntimeException if the engine cannot handle the template name + * * @api */ public function exists($name); @@ -60,7 +62,7 @@ interface EngineInterface /** * Returns true if this class is able to render the given template. * - * @param mixed $name A template name or a TemplateReferenceInterface instance + * @param string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance * * @return Boolean true if this class supports the given template, false otherwise * diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index 1da7f46ed9..324ebc7c79 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -71,15 +71,9 @@ class PhpEngine implements EngineInterface, \ArrayAccess } /** - * Renders a template. - * - * @param mixed $name A template name or a TemplateReferenceInterface instance - * @param array $parameters An array of parameters to pass to the template - * - * @return string The evaluated template as a string + * {@inheritdoc} * * @throws \InvalidArgumentException if the template does not exist - * @throws \RuntimeException if the template cannot be rendered * * @api */ @@ -112,11 +106,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess } /** - * Returns true if the template exists. - * - * @param mixed $name A template name or a TemplateReferenceInterface instance - * - * @return Boolean true if the template exists, false otherwise + * {@inheritdoc} * * @api */ @@ -132,11 +122,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess } /** - * Returns true if this class is able to render the given template. - * - * @param mixed $name A template name or a TemplateReferenceInterface instance - * - * @return Boolean true if this class supports the given resource, false otherwise + * {@inheritdoc} * * @api */ @@ -567,7 +553,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess /** * Loads the given template. * - * @param mixed $name A template name or a TemplateReferenceInterface instance + * @param string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance * * @return Storage A Storage instance * diff --git a/src/Symfony/Component/Templating/StreamingEngineInterface.php b/src/Symfony/Component/Templating/StreamingEngineInterface.php index 586f6b1de2..f8815f85f1 100644 --- a/src/Symfony/Component/Templating/StreamingEngineInterface.php +++ b/src/Symfony/Component/Templating/StreamingEngineInterface.php @@ -23,8 +23,8 @@ interface StreamingEngineInterface * * The implementation should output the content directly to the client. * - * @param mixed $name A template name or a TemplateReferenceInterface instance - * @param array $parameters An array of parameters to pass to the template + * @param string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance + * @param array $parameters An array of parameters to pass to the template * * @throws \RuntimeException if the template cannot be rendered * @throws \LogicException if the template cannot be streamed diff --git a/src/Symfony/Component/Templating/TemplateNameParser.php b/src/Symfony/Component/Templating/TemplateNameParser.php index 58bcacf890..f77f178c4e 100644 --- a/src/Symfony/Component/Templating/TemplateNameParser.php +++ b/src/Symfony/Component/Templating/TemplateNameParser.php @@ -27,11 +27,7 @@ use Symfony\Component\Templating\TemplateReference; class TemplateNameParser implements TemplateNameParserInterface { /** - * Parses a template to an array of parameters. - * - * @param string $name A template name - * - * @return TemplateReferenceInterface A template + * {@inheritdoc} * * @api */ diff --git a/src/Symfony/Component/Templating/TemplateNameParserInterface.php b/src/Symfony/Component/Templating/TemplateNameParserInterface.php index 6305f43be2..30df0c94f4 100644 --- a/src/Symfony/Component/Templating/TemplateNameParserInterface.php +++ b/src/Symfony/Component/Templating/TemplateNameParserInterface.php @@ -24,7 +24,7 @@ interface TemplateNameParserInterface /** * Convert a template name to a TemplateReferenceInterface instance. * - * @param string $name A template name + * @param string|TemplateReferenceInterface $name A template name or a TemplateReferenceInterface instance * * @return TemplateReferenceInterface A template * diff --git a/src/Symfony/Component/Templating/TemplateReference.php b/src/Symfony/Component/Templating/TemplateReference.php index 585bd7a2ad..560ee1a0f8 100644 --- a/src/Symfony/Component/Templating/TemplateReference.php +++ b/src/Symfony/Component/Templating/TemplateReference.php @@ -30,20 +30,16 @@ class TemplateReference implements TemplateReferenceInterface ); } + /** + * {@inheritdoc} + */ public function __toString() { return $this->getLogicalName(); } /** - * Sets a template parameter. - * - * @param string $name The parameter name - * @param string $value The parameter value - * - * @return TemplateReferenceInterface The TemplateReferenceInterface instance - * - * @throws \InvalidArgumentException if the parameter is not defined + * {@inheritdoc} * * @api */ @@ -59,13 +55,7 @@ class TemplateReference implements TemplateReferenceInterface } /** - * Gets a template parameter. - * - * @param string $name The parameter name - * - * @return string The parameter value - * - * @throws \InvalidArgumentException if the parameter is not defined + * {@inheritdoc} * * @api */ @@ -79,9 +69,7 @@ class TemplateReference implements TemplateReferenceInterface } /** - * Gets the template parameters. - * - * @return array An array of parameters + * {@inheritdoc} * * @api */ @@ -91,11 +79,7 @@ class TemplateReference implements TemplateReferenceInterface } /** - * Returns the path to the template. - * - * By default, it just returns the template name. - * - * @return string A path to the template or a resource + * {@inheritdoc} * * @api */ @@ -105,11 +89,7 @@ class TemplateReference implements TemplateReferenceInterface } /** - * Returns the "logical" template name. - * - * The template name acts as a unique identifier for the template. - * - * @return string The template name + * {@inheritdoc} * * @api */ diff --git a/src/Symfony/Component/Templating/TemplateReferenceInterface.php b/src/Symfony/Component/Templating/TemplateReferenceInterface.php index 60c910a1cd..d6b2ef43b5 100644 --- a/src/Symfony/Component/Templating/TemplateReferenceInterface.php +++ b/src/Symfony/Component/Templating/TemplateReferenceInterface.php @@ -37,7 +37,7 @@ interface TemplateReferenceInterface * * @return TemplateReferenceInterface The TemplateReferenceInterface instance * - * @throws \InvalidArgumentException if the parameter is not defined + * @throws \InvalidArgumentException if the parameter name is not supported * * @api */ @@ -50,7 +50,7 @@ interface TemplateReferenceInterface * * @return string The parameter value * - * @throws \InvalidArgumentException if the parameter is not defined + * @throws \InvalidArgumentException if the parameter name is not supported * * @api */ @@ -77,4 +77,15 @@ interface TemplateReferenceInterface * @api */ public function getLogicalName(); + + /** + * Returns the string representation as shortcut for getLogicalName(). + * + * Alias of getLogicalName(). + * + * @return string The template name + * + * @api + */ + public function __toString(); }