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