Skip to content

Commit d81d0a4

Browse files
committed
Deprecate Twig\ExpressionParser::parseOnlyArguments() and Twig\ExpressionParser::parseArguments()
1 parent 6513bc4 commit d81d0a4

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 3.19.0 (2025-XX-XX)
22

3+
* The `Twig\ExpressionParser::parseOnlyArguments()` and
4+
`Twig\ExpressionParser::parseArguments()` methods are deprecated, use
5+
`Twig\ExpressionParser::parseNamedArguments()` instead.
6+
37
* Fix `constant()` behavior when used with `??`
48
* Add the `invoke` filter
59
* Make `{}` optional for the `types` tag

doc/deprecated.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ Nodes
5656
as of Twig 3.12 as the tag is now automatically set by the Parser when
5757
needed.
5858

59-
* Passing a second argument to "ExpressionParser::parseFilterExpressionRaw()"
60-
is deprecated as of Twig 3.12.
61-
6259
* The following ``Twig\Node\Node`` methods will take a string or an integer
6360
(instead of just a string) in Twig 4.0 for their "name" argument:
6461
``getNode()``, ``hasNode()``, ``setNode()``, ``removeNode()``, and
@@ -213,6 +210,9 @@ Node Visitors
213210
Parser
214211
------
215212

213+
* Passing a second argument to ``ExpressionParser::parseFilterExpressionRaw()``
214+
is deprecated as of Twig 3.12.
215+
216216
* The following methods from ``Twig\Parser`` are deprecated as of Twig 3.12:
217217
``getBlockStack()``, ``hasBlock()``, ``getBlock()``, ``hasMacro()``,
218218
``hasTraits()``, ``getParent()``.
@@ -226,6 +226,10 @@ Parser
226226
* Passing ``null`` to ``Twig\Parser::setParent()`` is deprecated as of Twig
227227
3.12.
228228

229+
* The ``Twig\ExpressionParser::parseOnlyArguments()`` and
230+
``Twig\ExpressionParser::parseArguments()`` methods are deprecated, use
231+
``Twig\ExpressionParser::parseNamedArguments()`` instead.
232+
229233
Lexer
230234
-----
231235

extra/cache-extra/TokenParser/CacheTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function parse(Token $token): Node
3232
while ($stream->test(Token::NAME_TYPE)) {
3333
$k = $stream->getCurrent()->getValue();
3434
$stream->next();
35-
$args = $expressionParser->parseArguments();
35+
$args = $expressionParser->parseNamedArguments();
3636

3737
switch ($k) {
3838
case 'ttl':

extra/cache-extra/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"require": {
1818
"php": ">=8.0.2",
1919
"symfony/cache": "^5.4|^6.4|^7.0",
20-
"twig/twig": "^3.13|^4.0"
20+
"twig/twig": "^3.19|^4.0"
2121
},
2222
"require-dev": {
2323
"symfony/phpunit-bridge": "^6.4|^7.0"

src/ExpressionParser.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ public function getFunctionNode($name, $line)
530530
return new MacroReferenceExpression($alias['node']->getNode('var'), $alias['name'], $this->createArguments($line), $line);
531531
}
532532

533-
$args = $this->parseOnlyArguments();
533+
$args = $this->parseNamedArguments();
534534
$function = $this->getFunction($name, $line);
535535

536536
if ($function->getParserCallable()) {
@@ -579,7 +579,7 @@ public function parseFilterExpressionRaw($node)
579579
if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '(')) {
580580
$arguments = new EmptyNode();
581581
} else {
582-
$arguments = $this->parseOnlyArguments();
582+
$arguments = $this->parseNamedArguments();
583583
}
584584

585585
$filter = $this->getFilter($token->getValue(), $token->getLine());
@@ -611,9 +611,13 @@ public function parseFilterExpressionRaw($node)
611611
* @return Node
612612
*
613613
* @throws SyntaxError
614+
*
615+
* @deprecated since Twig 3.19 Use parseNamedArguments() instead
614616
*/
615617
public function parseArguments()
616618
{
619+
trigger_deprecation('twig/twig', '3.19', \sprintf('The "%s()" method is deprecated, use "%s::parseNamedArguments()" instead.', __METHOD__, __CLASS__));
620+
617621
$namedArguments = false;
618622
$definition = false;
619623
if (\func_num_args() > 1) {
@@ -738,7 +742,7 @@ private function parseTestExpression(Node $node): TestExpression
738742

739743
$arguments = null;
740744
if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
741-
$arguments = $this->parseOnlyArguments();
745+
$arguments = $this->parseNamedArguments();
742746
} elseif ($test->hasOneMandatoryArgument()) {
743747
$arguments = new Nodes([0 => $this->getPrimary()]);
744748
}
@@ -864,14 +868,24 @@ private function setDeprecationCheck(bool $deprecationCheck): bool
864868
private function createArguments(int $line): ArrayExpression
865869
{
866870
$arguments = new ArrayExpression([], $line);
867-
foreach ($this->parseOnlyArguments() as $k => $n) {
871+
foreach ($this->parseNamedArguments() as $k => $n) {
868872
$arguments->addElement($n, new LocalVariable($k, $line));
869873
}
870874

871875
return $arguments;
872876
}
873877

878+
/**
879+
* @deprecated since Twig 3.19 Use parseNamedArguments() instead
880+
*/
874881
public function parseOnlyArguments()
882+
{
883+
trigger_deprecation('twig/twig', '3.19', \sprintf('The "%s()" method is deprecated, use "%s::parseNamedArguments()" instead.', __METHOD__, __CLASS__));
884+
885+
return $this->parseNamedArguments();
886+
}
887+
888+
public function parseNamedArguments(): Nodes
875889
{
876890
$args = [];
877891
$stream = $this->parser->getStream();

0 commit comments

Comments
 (0)