From 4eaa29cfaeb61c0e3bf500da189a3199e22f71bc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 21 Oct 2016 17:34:50 -0700 Subject: [PATCH] removed obsolete code --- lib/Twig/Environment.php | 11 +-------- lib/Twig/Loader/Array.php | 14 ------------ lib/Twig/Loader/Chain.php | 27 +---------------------- lib/Twig/Loader/Filesystem.php | 10 --------- lib/Twig/LoaderInterface.php | 10 ++++----- lib/Twig/SourceContextLoaderInterface.php | 18 ++------------- lib/Twig/TokenStream.php | 2 +- test/Twig/Tests/EnvironmentTest.php | 4 +++- test/Twig/Tests/Loader/ArrayTest.php | 21 ------------------ test/Twig/Tests/Loader/ChainTest.php | 25 --------------------- 10 files changed, 12 insertions(+), 130 deletions(-) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 5b3435a11..80c3f2d26 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -530,10 +530,6 @@ class Twig_Environment */ public function setLoader(Twig_LoaderInterface $loader) { - if (!$loader instanceof Twig_SourceContextLoaderInterface && 0 !== strpos(get_class($loader), 'Mock_Twig_LoaderInterface')) { - @trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', get_class($loader)), E_USER_DEPRECATED); - } - $this->loader = $loader; } @@ -554,12 +550,7 @@ class Twig_Environment */ public function getSourceContext($name) { - $loader = $this->getLoader(); - if (!$loader instanceof Twig_SourceContextLoaderInterface) { - return new Twig_Source($loader->getSource($name), $name); - } - - return $loader->getSourceContext($name); + return $this->getLoader()->getSourceContext($name); } /** diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index 4cfc994b0..a131c3d98 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -46,20 +46,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf $this->templates[$name] = $template; } - /** - * {@inheritdoc} - */ - public function getSource($name) - { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); - - if (!isset($this->templates[$name])) { - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); - } - - return $this->templates[$name]; - } - /** * {@inheritdoc} */ diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index 010e68130..1b5b73986 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -42,27 +42,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf $this->hasSourceCache = array(); } - /** - * {@inheritdoc} - */ - public function getSource($name) - { - $exceptions = array(); - foreach ($this->loaders as $loader) { - if (!$loader->exists($name)) { - continue; - } - - try { - return $loader->getSource($name); - } catch (Twig_Error_Loader $e) { - $exceptions[] = $e->getMessage(); - } - } - - throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); - } - /** * {@inheritdoc} */ @@ -75,11 +54,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf } try { - if ($loader instanceof Twig_SourceContextLoaderInterface) { - return $loader->getSourceContext($name); - } - - return new Twig_Source($loader->getSource($name), $name); + return $loader->getSourceContext($name); } catch (Twig_Error_Loader $e) { $exceptions[] = $e->getMessage(); } diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index a6912d279..22eaf9fe6 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -133,16 +133,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI } } - /** - * {@inheritdoc} - */ - public function getSource($name) - { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); - - return file_get_contents($this->findTemplate($name)); - } - /** * {@inheritdoc} */ diff --git a/lib/Twig/LoaderInterface.php b/lib/Twig/LoaderInterface.php index df6d5ebef..11be062cb 100644 --- a/lib/Twig/LoaderInterface.php +++ b/lib/Twig/LoaderInterface.php @@ -17,17 +17,15 @@ interface Twig_LoaderInterface { /** - * Gets the source code of a template, given its name. + * Returns the source context for a given template logical name. * - * @param string $name The name of the template to load + * @param string $name The template logical name * - * @return string The template source code + * @return Twig_Source * * @throws Twig_Error_Loader When $name is not found - * - * @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface */ - public function getSource($name); + public function getSourceContext($name); /** * Gets the cache key to use for the cache for a given template name. diff --git a/lib/Twig/SourceContextLoaderInterface.php b/lib/Twig/SourceContextLoaderInterface.php index bb4115e80..b365bbf3e 100644 --- a/lib/Twig/SourceContextLoaderInterface.php +++ b/lib/Twig/SourceContextLoaderInterface.php @@ -10,22 +10,8 @@ */ /** - * Adds a getSourceContext() method for loaders. - * - * @author Fabien Potencier - * - * @deprecated since 1.27 (to be removed in 3.0) + * Empty interface for Twig 1.x compatibility. */ -interface Twig_SourceContextLoaderInterface +interface Twig_SourceContextLoaderInterface extends Twig_LoaderInterface { - /** - * Returns the source context for a given template logical name. - * - * @param string $name The template logical name - * - * @return Twig_Source - * - * @throws Twig_Error_Loader When $name is not found - */ - public function getSourceContext($name); } diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index 7df458f1e..f0e48dc5d 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -30,7 +30,7 @@ class Twig_TokenStream public function __construct(array $tokens, Twig_Source $source = null) { $this->tokens = $tokens; - $this->source = $source ?: new Twig_Source(''); + $this->source = $source ?: new Twig_Source('', ''); } /** diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index 81ea3afbc..3bea1a4e9 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -286,7 +286,9 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation() { - $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); + $loader = $this->getMockBuilder('Twig_LoaderInterface')->getMock(); + $twig = new Twig_Environment($loader); + $loader->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', ''))); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime()); $twig->loadTemplate(''); diff --git a/test/Twig/Tests/Loader/ArrayTest.php b/test/Twig/Tests/Loader/ArrayTest.php index d7f52ab55..f215e19ff 100644 --- a/test/Twig/Tests/Loader/ArrayTest.php +++ b/test/Twig/Tests/Loader/ArrayTest.php @@ -11,27 +11,6 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase { - /** - * @group legacy - */ - public function testGetSource() - { - $loader = new Twig_Loader_Array(array('foo' => 'bar')); - - $this->assertEquals('bar', $loader->getSource('foo')); - } - - /** - * @group legacy - * @expectedException Twig_Error_Loader - */ - public function testGetSourceWhenTemplateDoesNotExist() - { - $loader = new Twig_Loader_Array(array()); - - $loader->getSource('foo'); - } - /** * @expectedException Twig_Error_Loader */ diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php index ac0f72b4c..7ccffced7 100644 --- a/test/Twig/Tests/Loader/ChainTest.php +++ b/test/Twig/Tests/Loader/ChainTest.php @@ -11,20 +11,6 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase { - /** - * @group legacy - */ - public function testGetSource() - { - $loader = new Twig_Loader_Chain(array( - new Twig_Loader_Array(array('foo' => 'bar')), - new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')), - )); - - $this->assertEquals('bar', $loader->getSource('foo')); - $this->assertEquals('foo', $loader->getSource('bar')); - } - public function testGetSourceContext() { $path = dirname(__FILE__).'/../Fixtures'; @@ -56,17 +42,6 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase $loader->getSourceContext('foo'); } - /** - * @group legacy - * @expectedException Twig_Error_Loader - */ - public function testGetSourceWhenTemplateDoesNotExist() - { - $loader = new Twig_Loader_Chain(array()); - - $loader->getSource('foo'); - } - public function testGetCacheKey() { $loader = new Twig_Loader_Chain(array(