mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-06 15:37:58 +00:00
simplified code
This commit is contained in:
+4
-12
@@ -356,7 +356,7 @@ class Environment
|
||||
return new TemplateWrapper($this, $name);
|
||||
}
|
||||
|
||||
return new TemplateWrapper($this, $this->loadTemplate($name));
|
||||
return new TemplateWrapper($this, $this->loadTemplate($this->getTemplateClass($name), $name));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -376,15 +376,7 @@ class Environment
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function loadTemplate($name, $index = null)
|
||||
{
|
||||
return $this->loadClass($this->getTemplateClass($name), $name, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function loadClass($cls, $name, $index = null)
|
||||
public function loadTemplate(string $cls, string $name, int $index = null): Template
|
||||
{
|
||||
$mainCls = $cls;
|
||||
if (null !== $index) {
|
||||
@@ -459,7 +451,7 @@ class Environment
|
||||
|
||||
$this->setLoader($loader);
|
||||
try {
|
||||
return new TemplateWrapper($this, $this->loadTemplate($name));
|
||||
return new TemplateWrapper($this, $this->loadTemplate($this->getTemplateClass($name), $name));
|
||||
} finally {
|
||||
$this->setLoader($current);
|
||||
}
|
||||
@@ -510,7 +502,7 @@ class Environment
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->loadTemplate($name);
|
||||
return $this->load($name);
|
||||
} catch (LoaderError $e) {
|
||||
if (1 === \count($names)) {
|
||||
throw $e;
|
||||
|
||||
+3
-3
@@ -320,11 +320,11 @@ abstract class Template
|
||||
if (false !== $pos = strrpos($class, '___', -1)) {
|
||||
$class = substr($class, 0, $pos);
|
||||
}
|
||||
|
||||
return $this->env->loadClass($class, $template, $index);
|
||||
} else {
|
||||
$class = $this->env->getTemplateClass($template);
|
||||
}
|
||||
|
||||
return $this->env->loadTemplate($template, $index);
|
||||
return $this->env->loadTemplate($class, $template, $index);
|
||||
} catch (Error $e) {
|
||||
if (!$e->getSourceContext()) {
|
||||
$e->setSourceContext($templateName ? new Source('', $templateName) : $this->getSourceContext());
|
||||
|
||||
@@ -367,7 +367,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
$template = 'testFailLoadTemplate.twig';
|
||||
$twig = new Environment(new ArrayLoader([$template => false]));
|
||||
$twig->loadTemplate($template, 112233);
|
||||
$twig->loadTemplate($twig->getTemplateClass($template), $template, 112233);
|
||||
}
|
||||
|
||||
protected function getMockLoader($templateName, $templateContent)
|
||||
|
||||
Reference in New Issue
Block a user