Skip to content

Commit

Permalink
feature #2186 deprecated Twig_Template::getSource() in favor of Twig_…
Browse files Browse the repository at this point in the history
…Template::getSourceContext() (fabpot)

This PR was merged into the 1.x branch.

Discussion
----------

deprecated Twig_Template::getSource() in favor of Twig_Template::getSourceContext()

Commits
-------

7598f27 deprecated Twig_Template::getSource() in favor of Twig_Template::getSourceContext()
  • Loading branch information
fabpot committed Oct 17, 2016
2 parents b646e50 + 7598f27 commit 73e2c68
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions doc/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions lib/Twig/Node/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,10 @@ protected function compileDebugInfo(Twig_Compiler $compiler)
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")
Expand Down
4 changes: 4 additions & 0 deletions lib/Twig/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ public function getDebugInfo()
* 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 '';
}

Expand Down
9 changes: 9 additions & 0 deletions test/Twig/Tests/Node/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ public function getDebugInfo()
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 "";
}
Expand Down Expand Up @@ -137,8 +140,11 @@ public function getDebugInfo()
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 "";
}
Expand Down Expand Up @@ -196,8 +202,11 @@ public function getDebugInfo()
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 }}";
}
Expand Down

0 comments on commit 73e2c68

Please sign in to comment.