Move code from ExtendsTokenParser to Parser

This commit is contained in:
Fabien Potencier
2024-08-24 23:22:24 +02:00
parent e2f3435c81
commit cf4727606a
4 changed files with 12 additions and 3 deletions
+1
View File
@@ -1,5 +1,6 @@
# 3.12.0 (2024-XX-XX)
* Deprecate passing `null` to `Twig\Parser::setParent()`
* Update `Node::__toString()` to include the node tag if set
* Add support for integers in methods of `Twig\Node\Node` that take a Node name
* Deprecate not passing a `BodyNode` instance as the body of a `ModuleNode` or `MacroNode` constructor
+3
View File
@@ -166,6 +166,9 @@ Parser
* The ``Twig\ExpressionParser::parseArrayExpression()`` method is deprecated, use
``Twig\ExpressionParser::parseSequenceExpression()`` instead.
* Passing ``null`` to ``Twig\Parser::setParent()`` is deprecated as of Twig
3.12.
Templates
---------
+8
View File
@@ -292,6 +292,14 @@ class Parser
public function setParent(?Node $parent): void
{
if (null === $parent) {
trigger_deprecation('twig/twig', '3.12', 'Passing "null" to "%s()" is deprecated.', __METHOD__);
}
if (null !== $this->parent) {
throw new SyntaxError('Multiple extends tags are forbidden.', $parent->getTemplateLine(), $parent->getSourceContext());
}
$this->parent = $parent;
}
-3
View File
@@ -35,9 +35,6 @@ final class ExtendsTokenParser extends AbstractTokenParser
throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext());
}
if (null !== $this->parser->getParent()) {
throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext());
}
$this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
$stream->expect(Token::BLOCK_END_TYPE);