simplified code

This commit is contained in:
Fabien Potencier
2019-03-11 18:56:53 +01:00
parent e2103c87ae
commit 8ab1079842
+4 -15
View File
@@ -584,12 +584,12 @@ class Environment
/**
* Tries to load a template consecutively from an array.
*
* Similar to loadTemplate() but it also accepts instances of \Twig\Template and
* Similar to load() but it also accepts instances of \Twig\Template and
* \Twig\TemplateWrapper, and an array of templates where each is tried to be loaded.
*
* @param string|Template|\Twig\TemplateWrapper|array $names A template or an array of templates to try consecutively
*
* @return Template|Twig_TemplateWrapper
* @return TemplateWrapper
*
* @throws LoaderError When none of the templates can be found
* @throws SyntaxError When an error occurred during compilation
@@ -597,24 +597,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;
}
}
}