diff --git a/CHANGELOG b/CHANGELOG index 14ade7c7f..584756962 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.27.0 (2016-XX-XX) + * deprecated Twig_Template::getSource() in favor of Twig_Template::getSourceContext() * deprecated Twig_Node::getFilename() in favor of Twig_Node::getName() * deprecated the "filename" escaping strategy (use "name" instead) * added Twig_Source to hold information about the original template diff --git a/doc/deprecated.rst b/doc/deprecated.rst index f98f08924..9021b8f80 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -191,3 +191,6 @@ Miscellaneous ``Twig_Error::setTemplateFile()`` are deprecated. Use ``Twig_Error::getTemplateName()`` and ``Twig_Error::setTemplateName()`` instead. + +* As of Twig 1.27, ``Twig_Template::getSource()`` is deprecated. Use + ``Twig_Template::getSourceContext()`` instead. diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index aa9718fc3..341bc867a 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -412,8 +412,10 @@ class Twig_Node_Module extends Twig_Node protected function compileGetSource(Twig_Compiler $compiler) { $compiler + ->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n") ->write("public function getSource()\n", "{\n") ->indent() + ->write("@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);\n\n") ->write('return ') ->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '') ->raw(";\n") diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index f6141d324..be69651fc 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -58,9 +58,13 @@ abstract class Twig_Template implements Twig_TemplateInterface * Returns the template source code. * * @return string The template source code + * + * @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */ public function getSource() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); + return ''; } diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index 2e6810bda..04733a9ce 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -74,8 +74,11 @@ class __TwigTemplate_%x extends Twig_Template return array ( 19 => 1,); } + /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */ public function getSource() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); + return ""; } @@ -137,8 +140,11 @@ class __TwigTemplate_%x extends Twig_Template return array ( 26 => 1, 24 => 2, 11 => 1,); } + /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */ public function getSource() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); + return ""; } @@ -196,8 +202,11 @@ class __TwigTemplate_%x extends Twig_Template return array ( 17 => 2, 15 => 4, 9 => 2,); } + /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */ public function getSource() { + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); + return "{{ foo }}"; }