Browse code

removed unneeded abstraction

Fabien Potencier authored on 22/10/2016 03:23:53
Showing 3 changed files
... ...
@@ -403,7 +403,14 @@ class Twig_Environment
403 403
             }
404 404
 
405 405
             if (!class_exists($cls, false)) {
406
-                $content = $this->compileSource($this->getSourceContext($name));
406
+                $loader = $this->getLoader();
407
+                if (!$loader instanceof Twig_SourceContextLoaderInterface) {
408
+                    $source = new Twig_Source($loader->getSource($name), $name);
409
+                } else {
410
+                    $source = $loader->getSourceContext($name);
411
+                }
412
+
413
+                $content = $this->compileSource($source);
407 414
 
408 415
                 if ($this->bcWriteCacheFile) {
409 416
                     $this->writeCacheFile($key, $content);
... ...
@@ -751,21 +758,6 @@ class Twig_Environment
751 758
     }
752 759
 
753 760
     /**
754
-     * Gets the source context for the given template name.
755
-     *
756
-     * @return Twig_Source
757
-     */
758
-    public function getSourceContext($name)
759
-    {
760
-        $loader = $this->getLoader();
761
-        if (!$loader instanceof Twig_SourceContextLoaderInterface) {
762
-            return new Twig_Source($loader->getSource($name), $name);
763
-        }
764
-
765
-        return $loader->getSourceContext($name);
766
-    }
767
-
768
-    /**
769 761
      * Sets the default template charset.
770 762
      *
771 763
      * @param string $charset The default charset
... ...
@@ -1489,8 +1489,13 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
1489 1489
  */
1490 1490
 function twig_source(Twig_Environment $env, $name, $ignoreMissing = false)
1491 1491
 {
1492
+    $loader = $env->getLoader();
1492 1493
     try {
1493
-        return $env->getSourceContext($name)->getCode();
1494
+        if (!$loader instanceof Twig_SourceContextLoaderInterface) {
1495
+            return $loader->getSource($name);
1496
+        } else {
1497
+            return $loader->getSourceContext($name)->getCode();
1498
+        }
1494 1499
     } catch (Twig_Error_Loader $e) {
1495 1500
         if (!$ignoreMissing) {
1496 1501
             throw $e;
... ...
@@ -212,7 +212,13 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
212 212
 
213 213
                 foreach (array_keys($templates) as $name) {
214 214
                     echo "Template: $name\n";
215
-                    echo $twig->compile($twig->parse($twig->tokenize($twig->getSourceContext($name), $name)));
215
+                    $loader = $twig->getLoader();
216
+                    if (!$loader instanceof Twig_SourceContextLoaderInterface) {
217
+                        $source = new Twig_Source($loader->getSource($name), $name);
218
+                    } else {
219
+                        $source = $loader->getSourceContext($name);
220
+                    }
221
+                    echo $twig->compile($twig->parse($twig->tokenize($source)));
216 222
                 }
217 223
             }
218 224
             $this->assertEquals($expected, $output, $message.' (in '.$file.')');