From 2d66fa85a528dbeb92b659c7cc812fc85e1607af Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 12 Jan 2019 03:31:07 +0100 Subject: [PATCH] deprecated passing a string as a source on Twig_Error --- CHANGELOG | 1 + doc/deprecated.rst | 6 ++++++ lib/Twig/Error.php | 2 +- lib/Twig/Template.php | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ea6044488..7117de127 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 2.6.1 (2018-XX-XX) + * deprecated passing a string as a source on Twig_Error * switched generated code to use the PHP short array notation * 2.6.0 (2018-12-16) diff --git a/doc/deprecated.rst b/doc/deprecated.rst index 2a5ceb778..f96766da9 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -13,6 +13,12 @@ Inheritance ``Twig_Error_Syntax`` exception. It does not work anyway, so most projects won't need to do anything to upgrade. +Errors +------ + + * Passing a string as the ``$source`` argument on ``Twig_Error`` constructor is + deprecated since Twig 2.6.1. Pass an instance of ``Twig_Source`` instead. + Tags ---- diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 13ec6cd6e..1f3685207 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -63,7 +63,7 @@ class Twig_Error extends Exception if (null === $source) { $name = null; } elseif (!$source instanceof Twig_Source) { - // for compat with the Twig C ext., passing the template name as string is accepted + @trigger_error(sprintf('Passing a string as a source to %s is deprecated since version 2.6.1; pass a Twig_Source instance instead.', __CLASS__), E_USER_DEPRECATED); $name = $source; } else { $name = $source->getName(); diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 701a34fc8..98b1dfdaf 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -206,9 +206,9 @@ abstract class Twig_Template } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); } elseif (isset($blocks[$name])) { - throw new Twig_Error_Runtime(sprintf('Block "%s" should not call parent() in "%s" as the block does not exist in the parent template "%s".', $name, $blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1, $blocks[$name][0]->getTemplateName()); + throw new Twig_Error_Runtime(sprintf('Block "%s" should not call parent() in "%s" as the block does not exist in the parent template "%s".', $name, $blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1, $blocks[$name][0]->getSourceContext()); } else { - throw new Twig_Error_Runtime(sprintf('Block "%s" on template "%s" does not exist.', $name, $this->getTemplateName()), -1, $this->getTemplateName()); + throw new Twig_Error_Runtime(sprintf('Block "%s" on template "%s" does not exist.', $name, $this->getTemplateName()), -1, $this->getSourceContext()); } }