feature #2958 Change Environment::resolveTemplate() to always return a TemplateWrapper (fabpot)

This PR was merged into the 3.x branch.

Discussion
----------

Change Environment::resolveTemplate() to always return a TemplateWrapper

Commits
-------

e1e9d011 changed Environment::resolveTemplate() to always return a TemplateWrapper
This commit is contained in:
Fabien Potencier
2019-04-23 17:51:44 +02:00
+2 -12
View File
@@ -482,7 +482,7 @@ class Environment
*
* @param string|TemplateWrapper|array $names A template or an array of templates to try consecutively
*
* @return TemplateWrapper|Template
* @return TemplateWrapper
*
* @throws LoaderError When none of the templates can be found
* @throws SyntaxError When an error occurred during compilation
@@ -490,23 +490,13 @@ class Environment
public function resolveTemplate($names)
{
if (!\is_array($names)) {
$names = [$names];
return $this->load($names);
}
foreach ($names as $name) {
if ($name instanceof Template) {
return $name;
}
if ($name instanceof TemplateWrapper) {
return $name;
}
try {
return $this->load($name);
} catch (LoaderError $e) {
if (1 === \count($names)) {
throw $e;
}
}
}