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

This commit is contained in:
Fabien Potencier
2019-03-15 17:37:45 +01:00
parent 8613aad80c
commit e1e9d0114d
+3 -13
View File
@@ -490,7 +490,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
@@ -498,23 +498,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->loadTemplate($name);
return $this->load($name);
} catch (LoaderError $e) {
if (1 === \count($names)) {
throw $e;
}
}
}