removed unneeded abstraction

This commit is contained in:
Fabien Potencier
2016-10-21 20:23:53 -07:00
parent d6e60740d9
commit 09bf2bae50
3 changed files with 21 additions and 18 deletions
+8 -16
View File
@@ -403,7 +403,14 @@ class Twig_Environment
}
if (!class_exists($cls, false)) {
$content = $this->compileSource($this->getSourceContext($name));
$loader = $this->getLoader();
if (!$loader instanceof Twig_SourceContextLoaderInterface) {
$source = new Twig_Source($loader->getSource($name), $name);
} else {
$source = $loader->getSourceContext($name);
}
$content = $this->compileSource($source);
if ($this->bcWriteCacheFile) {
$this->writeCacheFile($key, $content);
@@ -750,21 +757,6 @@ class Twig_Environment
return $this->loader;
}
/**
* Gets the source context for the given template name.
*
* @return Twig_Source
*/
public function getSourceContext($name)
{
$loader = $this->getLoader();
if (!$loader instanceof Twig_SourceContextLoaderInterface) {
return new Twig_Source($loader->getSource($name), $name);
}
return $loader->getSourceContext($name);
}
/**
* Sets the default template charset.
*
+6 -1
View File
@@ -1489,8 +1489,13 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
*/
function twig_source(Twig_Environment $env, $name, $ignoreMissing = false)
{
$loader = $env->getLoader();
try {
return $env->getSourceContext($name)->getCode();
if (!$loader instanceof Twig_SourceContextLoaderInterface) {
return $loader->getSource($name);
} else {
return $loader->getSourceContext($name)->getCode();
}
} catch (Twig_Error_Loader $e) {
if (!$ignoreMissing) {
throw $e;
+7 -1
View File
@@ -212,7 +212,13 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
foreach (array_keys($templates) as $name) {
echo "Template: $name\n";
echo $twig->compile($twig->parse($twig->tokenize($twig->getSourceContext($name), $name)));
$loader = $twig->getLoader();
if (!$loader instanceof Twig_SourceContextLoaderInterface) {
$source = new Twig_Source($loader->getSource($name), $name);
} else {
$source = $loader->getSourceContext($name);
}
echo $twig->compile($twig->parse($twig->tokenize($source)));
}
}
$this->assertEquals($expected, $output, $message.' (in '.$file.')');