Deprecate Twig\ExpressionParser::parseOnlyArguments() and Twig\ExpressionParser::parseArguments()

This commit is contained in:
Fabien Potencier
2025-01-22 20:59:41 +01:00
parent 6513bc48f0
commit 960f6762ed
5 changed files with 31 additions and 9 deletions
+4
View File
@@ -1,5 +1,9 @@
# 3.19.0 (2025-XX-XX)
* Deprecate `Twig\ExpressionParser::parseOnlyArguments()` and
`Twig\ExpressionParser::parseArguments()` (use
`Twig\ExpressionParser::parseNamedArguments()` instead)
* Fix `constant()` behavior when used with `??`
* Add the `invoke` filter
* Make `{}` optional for the `types` tag
+7 -3
View File
@@ -56,9 +56,6 @@ Nodes
as of Twig 3.12 as the tag is now automatically set by the Parser when
needed.
* Passing a second argument to "ExpressionParser::parseFilterExpressionRaw()"
is deprecated as of Twig 3.12.
* The following ``Twig\Node\Node`` methods will take a string or an integer
(instead of just a string) in Twig 4.0 for their "name" argument:
``getNode()``, ``hasNode()``, ``setNode()``, ``removeNode()``, and
@@ -213,6 +210,9 @@ Node Visitors
Parser
------
* Passing a second argument to ``ExpressionParser::parseFilterExpressionRaw()``
is deprecated as of Twig 3.12.
* The following methods from ``Twig\Parser`` are deprecated as of Twig 3.12:
``getBlockStack()``, ``hasBlock()``, ``getBlock()``, ``hasMacro()``,
``hasTraits()``, ``getParent()``.
@@ -226,6 +226,10 @@ Parser
* Passing ``null`` to ``Twig\Parser::setParent()`` is deprecated as of Twig
3.12.
* The ``Twig\ExpressionParser::parseOnlyArguments()`` and
``Twig\ExpressionParser::parseArguments()`` methods are deprecated, use
``Twig\ExpressionParser::parseNamedArguments()`` instead.
Lexer
-----
@@ -32,7 +32,7 @@ class CacheTokenParser extends AbstractTokenParser
while ($stream->test(Token::NAME_TYPE)) {
$k = $stream->getCurrent()->getValue();
$stream->next();
$args = $expressionParser->parseArguments();
$args = $expressionParser->parseNamedArguments();
switch ($k) {
case 'ttl':
+1 -1
View File
@@ -17,7 +17,7 @@
"require": {
"php": ">=8.0.2",
"symfony/cache": "^5.4|^6.4|^7.0",
"twig/twig": "^3.13|^4.0"
"twig/twig": "^3.19|^4.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^6.4|^7.0"
+18 -4
View File
@@ -530,7 +530,7 @@ class ExpressionParser
return new MacroReferenceExpression($alias['node']->getNode('var'), $alias['name'], $this->createArguments($line), $line);
}
$args = $this->parseOnlyArguments();
$args = $this->parseNamedArguments();
$function = $this->getFunction($name, $line);
if ($function->getParserCallable()) {
@@ -579,7 +579,7 @@ class ExpressionParser
if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '(')) {
$arguments = new EmptyNode();
} else {
$arguments = $this->parseOnlyArguments();
$arguments = $this->parseNamedArguments();
}
$filter = $this->getFilter($token->getValue(), $token->getLine());
@@ -611,9 +611,13 @@ class ExpressionParser
* @return Node
*
* @throws SyntaxError
*
* @deprecated since Twig 3.19 Use parseNamedArguments() instead
*/
public function parseArguments()
{
trigger_deprecation('twig/twig', '3.19', \sprintf('The "%s()" method is deprecated, use "%s::parseNamedArguments()" instead.', __METHOD__, __CLASS__));
$namedArguments = false;
$definition = false;
if (\func_num_args() > 1) {
@@ -738,7 +742,7 @@ class ExpressionParser
$arguments = null;
if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
$arguments = $this->parseOnlyArguments();
$arguments = $this->parseNamedArguments();
} elseif ($test->hasOneMandatoryArgument()) {
$arguments = new Nodes([0 => $this->getPrimary()]);
}
@@ -864,14 +868,24 @@ class ExpressionParser
private function createArguments(int $line): ArrayExpression
{
$arguments = new ArrayExpression([], $line);
foreach ($this->parseOnlyArguments() as $k => $n) {
foreach ($this->parseNamedArguments() as $k => $n) {
$arguments->addElement($n, new LocalVariable($k, $line));
}
return $arguments;
}
/**
* @deprecated since Twig 3.19 Use parseNamedArguments() instead
*/
public function parseOnlyArguments()
{
trigger_deprecation('twig/twig', '3.19', \sprintf('The "%s()" method is deprecated, use "%s::parseNamedArguments()" instead.', __METHOD__, __CLASS__));
return $this->parseNamedArguments();
}
public function parseNamedArguments(): Nodes
{
$args = [];
$stream = $this->parser->getStream();