-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
``deprecated`` | ||
============== | ||
|
||
.. versionadded:: 1.36 and 2.5 | ||
The ``deprecated`` tag was added in Twig 1.36 and 2.5. | ||
|
||
Twig generates a deprecation notice (via a call to the ``trigger_error()`` | ||
PHP function) where the ``deprecated`` tag is used in a template: | ||
|
||
.. code-block:: jinja | ||
{# base.twig #} | ||
{% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %} | ||
{% extends 'layout.twig' %} | ||
Also you can deprecate a block in the following way: | ||
|
||
.. code-block:: jinja | ||
{% block hey %} | ||
{% deprecated 'The "hey" block in "blocks.twig" template is deprecated, use "greet" block instead.' %} | ||
{{ block('greet') }} | ||
{% endblock %} | ||
{% block greet %} | ||
Hey you! | ||
{% endblock %} | ||
Note that by default, the deprecation notices are silenced and never displayed nor logged. | ||
See :ref:`deprecation-notices` to learn how to handle them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ Tags | |
use | ||
verbatim | ||
with | ||
deprecated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Represents a deprecated node. | ||
* | ||
* @author Yonel Ceruto <yonelceruto@gmail.com> | ||
*/ | ||
class Twig_Node_Deprecated extends Twig_Node | ||
{ | ||
public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) | ||
{ | ||
parent::__construct(array('expr' => $expr), array(), $lineno, $tag); | ||
} | ||
|
||
public function compile(Twig_Compiler $compiler) | ||
{ | ||
$compiler | ||
->addDebugInfo($this) | ||
->write('@trigger_error(') | ||
->subcompile($this->getNode('expr')) | ||
->raw('.') | ||
->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine())) | ||
->raw(", E_USER_DEPRECATED);\n") | ||
; | ||
} | ||
} | ||
|
||
class_alias('Twig_Node_Deprecated', 'Twig\Node\DeprecatedNode', false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Deprecates a section of a template. | ||
* | ||
* <pre> | ||
* {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %} | ||
* | ||
* {% extends 'layout.html.twig' %} | ||
* </pre> | ||
* | ||
* @author Yonel Ceruto <yonelceruto@gmail.com> | ||
* | ||
* @final | ||
*/ | ||
class Twig_TokenParser_Deprecated extends Twig_TokenParser | ||
{ | ||
public function parse(Twig_Token $token) | ||
{ | ||
$expr = $this->parser->getExpressionParser()->parseExpression(); | ||
|
||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); | ||
|
||
return new Twig_Node_Deprecated($expr, $token->getLine(), $this->getTag()); | ||
} | ||
|
||
public function getTag() | ||
{ | ||
return 'deprecated'; | ||
} | ||
} | ||
|
||
class_alias('Twig_TokenParser_Deprecated', 'Twig\TokenParser\DeprecatedTokenParser', false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Twig\Node; | ||
|
||
class_exists('Twig_Node_Deprecated'); | ||
|
||
if (\false) { | ||
class DeprecatedNode extends \Twig_Node_Deprecated | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Twig\TokenParser; | ||
|
||
class_exists('Twig_TokenParser_Deprecated'); | ||
|
||
if (\false) { | ||
class DeprecatedTokenParser extends \Twig_TokenParser_Deprecated | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
class Twig_Tests_Node_DeprecatedTest extends Twig_Test_NodeTestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$expr = new Twig_Node_Expression_Constant('foo', 1); | ||
$node = new Twig_Node_Deprecated($expr, 1); | ||
|
||
$this->assertEquals($expr, $node->getNode('expr')); | ||
} | ||
|
||
public function getTests() | ||
{ | ||
$tests = array(); | ||
|
||
$expr = new Twig_Node_Expression_Constant('This section is deprecated', 1); | ||
$node = new Twig_Node_Deprecated($expr, 1, 'deprecated'); | ||
$node->setTemplateName('foo.twig'); | ||
|
||
$tests[] = array($node, <<<EOF | ||
// line 1 | ||
@trigger_error("This section is deprecated"." (\"foo.twig\" at line 1).", E_USER_DEPRECATED); | ||
EOF | ||
); | ||
|
||
$t = new Twig_Node(array( | ||
new Twig_Node_Expression_Constant(true, 1), | ||
new Twig_Node_Deprecated($expr, 2, 'deprecated'), | ||
), array(), 1); | ||
$node = new Twig_Node_If($t, null, 1); | ||
$node->setTemplateName('foo.twig'); | ||
|
||
$tests[] = array($node, <<<EOF | ||
// line 1 | ||
if (true) { | ||
// line 2 | ||
@trigger_error("This section is deprecated"." (\"foo.twig\" at line 2).", E_USER_DEPRECATED); | ||
} | ||
EOF | ||
); | ||
|
||
return $tests; | ||
} | ||
} |