-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #4183 Add support for package/version on deprecations (fabpot)
This PR was merged into the 3.x branch. Discussion ---------- Add support for package/version on deprecations Commits ------- 0ce79df Use trigger_deprecation() instead of trigger_error() for deprecations
- Loading branch information
Showing
13 changed files
with
131 additions
and
30 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
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
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
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Twig\TokenParser; | ||
|
||
use Twig\Error\SyntaxError; | ||
use Twig\Node\DeprecatedNode; | ||
use Twig\Node\Node; | ||
use Twig\Token; | ||
|
@@ -21,6 +22,8 @@ | |
* {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %} | ||
* {% extends 'layout.html.twig' %} | ||
* | ||
* {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' package="foo/bar" version="1.1" %} | ||
* | ||
* @author Yonel Ceruto <[email protected]> | ||
* | ||
* @internal | ||
|
@@ -29,11 +32,31 @@ final class DeprecatedTokenParser extends AbstractTokenParser | |
{ | ||
public function parse(Token $token): Node | ||
{ | ||
$expr = $this->parser->getExpressionParser()->parseExpression(); | ||
$stream = $this->parser->getStream(); | ||
$expressionParser = $this->parser->getExpressionParser(); | ||
$expr = $expressionParser->parseExpression(); | ||
$node = new DeprecatedNode($expr, $token->getLine(), $this->getTag()); | ||
|
||
while ($stream->test(Token::NAME_TYPE)) { | ||
$k = $stream->getCurrent()->getValue(); | ||
$stream->next(); | ||
$stream->expect(Token::OPERATOR_TYPE, '='); | ||
|
||
switch ($k) { | ||
case 'package': | ||
$node->setNode('package', $expressionParser->parseExpression()); | ||
break; | ||
case 'version': | ||
$node->setNode('version', $expressionParser->parseExpression()); | ||
break; | ||
default: | ||
throw new SyntaxError(\sprintf('Unknown "%s" option.', $k), $stream->getCurrent()->getLine(), $stream->getSourceContext()); | ||
} | ||
} | ||
|
||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE); | ||
$stream->expect(Token::BLOCK_END_TYPE); | ||
|
||
return new DeprecatedNode($expr, $token->getLine(), $this->getTag()); | ||
return $node; | ||
} | ||
|
||
public function getTag(): string | ||
|
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
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,10 @@ | ||
--TEST-- | ||
Deprecating a template with "deprecated" tag | ||
--TEMPLATE-- | ||
{% deprecated 'The "index.twig" template is deprecated, use "greeting.twig" instead.' package="foo/bar" %} | ||
|
||
Hello Fabien | ||
--DATA-- | ||
return [] | ||
--EXPECT-- | ||
Hello Fabien |
10 changes: 10 additions & 0 deletions
10
tests/Fixtures/tags/deprecated/with_package_version.legacy.test
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,10 @@ | ||
--TEST-- | ||
Deprecating a template with "deprecated" tag | ||
--TEMPLATE-- | ||
{% deprecated 'The "index.twig" template is deprecated, use "greeting.twig" instead.' package="foo/bar" version=1.1 %} | ||
|
||
Hello Fabien | ||
--DATA-- | ||
return [] | ||
--EXPECT-- | ||
Hello Fabien |
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