From 714360d612925560feb2a7d90bed605ba667945a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Mar 2019 17:49:02 +0100 Subject: [PATCH 1/4] marked Twig\Environment::getTemplateClass() as internal --- CHANGELOG | 1 + src/Environment.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index b27d29ae2..409225324 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 2.7.0 (2019-XX-XX) + * marked Twig\Environment::getTemplateClass() as internal (implementation detail) * improved the performance of the sandbox * deprecated the spaceless tag * added a spaceless filter diff --git a/src/Environment.php b/src/Environment.php index 188ef05af..c3506ffdb 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -293,6 +293,8 @@ class Environment * @param int|null $index The index if it is an embedded template * * @return string The template class name + * + * @internal */ public function getTemplateClass($name, $index = null) { From d9b91a257e9514216f2bc2544f61f2e5fef1cf40 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Mar 2019 17:54:51 +0100 Subject: [PATCH 2/4] added the possibility to pass a TemplateWrapper to Twig\Environment::load() --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 409225324..c3577eccc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 2.7.0 (2019-XX-XX) + * added the possibility to pass a TemplateWrapper to Twig\Environment::load() * marked Twig\Environment::getTemplateClass() as internal (implementation detail) * improved the performance of the sandbox * deprecated the spaceless tag From a4476dfc786092b4ad568992c7951e41e2a364d5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Mar 2019 18:50:02 +0100 Subject: [PATCH 3/4] updated docs --- doc/deprecated.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/deprecated.rst b/doc/deprecated.rst index ac0a338ef..26b51a10c 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -65,6 +65,9 @@ Environment ``Twig\Environment::setBaseTemplateClass()`` methods are deprecated and will be removed in Twig 3.0. +* As of Twig 2.7, the ``Twig\Environment::getTemplateClass()`` is marked as + being internal and should not be used. + Interfaces ---------- From b5da9b5aa7c5d939bdd7a37626e68dc3d577446b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Mar 2019 18:59:16 +0100 Subject: [PATCH 4/4] deprecated passing a Twig\Template to load()/resolveTemplate() --- CHANGELOG | 1 + doc/deprecated.rst | 4 ++++ src/Environment.php | 7 ++++--- test/Twig/Tests/TemplateWrapperTest.php | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c3577eccc..eb75f3a26 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 2.7.0 (2019-XX-XX) + * deprecated passing a Twig\Template to Twig\Environment::load()/Twig\Environment::resolveTemplate() * added the possibility to pass a TemplateWrapper to Twig\Environment::load() * marked Twig\Environment::getTemplateClass() as internal (implementation detail) * improved the performance of the sandbox diff --git a/doc/deprecated.rst b/doc/deprecated.rst index 26b51a10c..b7ab63bfc 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -68,6 +68,10 @@ Environment * As of Twig 2.7, the ``Twig\Environment::getTemplateClass()`` is marked as being internal and should not be used. +* As of Twig 2.7, passing a ``Twig\Template`` instance to the + ``Twig\Environment::load()`` and ``Twig\Environment::resolveTemplate()`` is + deprecated. + Interfaces ---------- diff --git a/src/Environment.php b/src/Environment.php index c3506ffdb..82afadc4a 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -29,7 +29,6 @@ use Twig\Node\ModuleNode; use Twig\Node\Node; use Twig\NodeVisitor\NodeVisitorInterface; use Twig\RuntimeLoader\RuntimeLoaderInterface; -use Twig\Template; use Twig\TokenParser\TokenParserInterface; /** @@ -338,7 +337,7 @@ class Environment /** * Loads a template. * - * @param string|TemplateWrapper|Template $name The template name + * @param string|TemplateWrapper $name The template name * * @throws LoaderError When the template cannot be found * @throws RuntimeError When a previously generated cache is corrupted @@ -353,6 +352,8 @@ class Environment } if ($name instanceof Template) { + @trigger_error('Passing a \Twig\Template instance to '.__METHOD__.' is deprecated since Twig 2.7.0, use \Twig\TemplateWrapper instead.', E_USER_DEPRECATED); + return new TemplateWrapper($this, $name); } @@ -485,7 +486,7 @@ class Environment * Similar to load() but it also accepts instances of \Twig\Template and * \Twig\TemplateWrapper, and an array of templates where each is tried to be loaded. * - * @param string|Template|TemplateWrapper|array $names A template or an array of templates to try consecutively + * @param string|TemplateWrapper|array $names A template or an array of templates to try consecutively * * @return TemplateWrapper * diff --git a/test/Twig/Tests/TemplateWrapperTest.php b/test/Twig/Tests/TemplateWrapperTest.php index 96ca9b01c..74618406c 100644 --- a/test/Twig/Tests/TemplateWrapperTest.php +++ b/test/Twig/Tests/TemplateWrapperTest.php @@ -11,7 +11,6 @@ use Twig\Environment; use Twig\Loader\ArrayLoader; -use Twig\TemplateWrapper; class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase {