From 379f0c3553fcc3b4ebd0bc56e48036fa85bfdbbb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Mar 2019 11:51:00 +0100 Subject: [PATCH] added soe missing deprecations --- CHANGELOG | 6 ++++-- doc/deprecated.rst | 17 +++++++++++++++++ lib/Twig/SimpleFilter.php | 3 +++ lib/Twig/SimpleFunction.php | 3 +++ lib/Twig/SimpleTest.php | 3 +++ src/Extension/InitRuntimeInterface.php | 2 ++ src/ExtensionSet.php | 2 ++ src/Loader/ExistsLoaderInterface.php | 2 ++ test/Twig/Tests/EnvironmentTest.php | 3 +++ 9 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9a557dc13..1a57e8649 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,12 +1,14 @@ * 2.7.0 (2019-XX-XX) + * deprecated Twig\Extension\InitRuntimeInterface + * deprecated Twig\Loader\ExistsLoaderInterface * deprecated PSR-0 classes in favor of namespaced ones * made namespace classes the default classes (PSR-0 ones are aliases now) * added Twig\Loader\ChainLoader::getLoaders() * removed duplicated directory separator in FilesystemLoader * deprecated the "base_template_class" option on Twig\Environment - * deprecated the ``Twig\Environment::getBaseTemplateClass()`` and - ``Twig\Environment::setBaseTemplateClass()`` methods + * deprecated the Twig\Environment::getBaseTemplateClass() and + Twig\Environment::setBaseTemplateClass() methods * changed internal code to use the namespaced classes as much as possible * deprecated Twig_Parser::isReservedMacroName() diff --git a/doc/deprecated.rst b/doc/deprecated.rst index 4302d9085..fa3fccaef 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -60,3 +60,20 @@ Environment * As of Twig 2.7, the ``Twig\Environment::getBaseTemplateClass()`` and ``Twig\Environment::setBaseTemplateClass()`` methods are deprecated and will be removed in Twig 3.0. + +Interfaces +---------- + +* As of Twig 2.7, the empty ``Twig\Loader\ExistsLoaderInterface`` interface is + deprecated and will be removed in Twig 3.0. + +* As of Twig 2.7, the ``Twig\Extension\InitRuntimeInterface`` interface is + deprecated and will be removed in Twig 3.0. + +Miscellaneous +------------- + +* As of Twig 2.7, the ``Twig_SimpleFilter``, ``Twig_SimpleFunction``, and + ``Twig_SimpleTest`` empty classes are deprecated and will be removed in Twig + 3.0. Use ``Twig\TwigFilter``, ``Twig\TwigFunction``, and ``Twig\TwigTest`` + respectively. diff --git a/lib/Twig/SimpleFilter.php b/lib/Twig/SimpleFilter.php index ca2fe7f53..8c59f5ff7 100644 --- a/lib/Twig/SimpleFilter.php +++ b/lib/Twig/SimpleFilter.php @@ -16,7 +16,10 @@ use Twig\TwigFilter; */ class_exists(TwigFilter::class); +@trigger_error(sprintf('Using the "Twig_SimpleFilter" class is deprecated since Twig version 2.7, use "Twig\TwigFilter" instead.'), E_USER_DEPRECATED); + if (false) { + /** @deprecated since Twig 2.7, use "Twig\TwigFilter" instead */ final class Twig_SimpleFilter extends TwigFilter { } diff --git a/lib/Twig/SimpleFunction.php b/lib/Twig/SimpleFunction.php index f76028883..989a8de4b 100644 --- a/lib/Twig/SimpleFunction.php +++ b/lib/Twig/SimpleFunction.php @@ -16,7 +16,10 @@ use Twig\TwigFunction; */ class_exists(TwigFunction::class); +@trigger_error(sprintf('Using the "Twig_SimpleFunction" class is deprecated since Twig version 2.7, use "Twig\TwigFunction" instead.'), E_USER_DEPRECATED); + if (false) { + /** @deprecated since Twig 2.7, use "Twig\TwigFunction" instead */ final class Twig_SimpleFunction extends TwigFunction { } diff --git a/lib/Twig/SimpleTest.php b/lib/Twig/SimpleTest.php index 75cb5af52..3e101b3e4 100644 --- a/lib/Twig/SimpleTest.php +++ b/lib/Twig/SimpleTest.php @@ -16,7 +16,10 @@ use Twig\TwigTest; */ class_exists(TwigTest::class); +@trigger_error(sprintf('Using the "Twig_SimpleTest" class is deprecated since Twig version 2.7, use "Twig\TwigTest" instead.'), E_USER_DEPRECATED); + if (false) { + /** @deprecated since Twig 2.7, use "Twig\TwigTest" instead */ final class Twig_SimpleTest extends TwigTest { } diff --git a/src/Extension/InitRuntimeInterface.php b/src/Extension/InitRuntimeInterface.php index 54bdd4080..5c0ad3fbf 100644 --- a/src/Extension/InitRuntimeInterface.php +++ b/src/Extension/InitRuntimeInterface.php @@ -20,6 +20,8 @@ use Twig\Environment; * deprecated initRuntime() method in your extensions. * * @author Fabien Potencier + * + * @deprecated since version 2.7, to be removed in 3.0 */ interface InitRuntimeInterface { diff --git a/src/ExtensionSet.php b/src/ExtensionSet.php index e7e32b804..3fd7ba2f8 100644 --- a/src/ExtensionSet.php +++ b/src/ExtensionSet.php @@ -60,6 +60,8 @@ final class ExtensionSet foreach ($this->extensions as $extension) { if ($extension instanceof InitRuntimeInterface) { + @trigger_error(sprintf('Implementing \Twig\Extension\InitRuntimeInterface on "%s" is deprecated since Twig 2.7 as the interface will be removed in 3.0.', get_class($extension)), E_USER_DEPRECATED); + $extension->initRuntime($env); } } diff --git a/src/Loader/ExistsLoaderInterface.php b/src/Loader/ExistsLoaderInterface.php index c6c4febd5..f61e7a013 100644 --- a/src/Loader/ExistsLoaderInterface.php +++ b/src/Loader/ExistsLoaderInterface.php @@ -13,6 +13,8 @@ namespace Twig\Loader; /** * Empty interface for Twig 1.x compatibility. + * + * @deprecated since version 2.7, to be removed in 3.0 */ interface ExistsLoaderInterface extends LoaderInterface { diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index aa23fcd00..b76e8ecf8 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -308,6 +308,9 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $this->assertTrue($twig->isTemplateFresh('page', time())); } + /** + * @group legacy + */ public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation() { $loader = $this->getMockBuilder(LoaderInterface::class)->getMock();