mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-08 00:17:29 +00:00
simplified code
This commit is contained in:
+4
-15
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user