8000 [TwigBridge] remove remaining BC layers by xabbuh · Pull Request #59893 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] remove remaining BC layers #59893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading 8000
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Symfony/Bridge/Twig/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Node;
use Twig\Node\TextNode;
Expand Down Expand Up @@ -120,7 +119,7 @@ private function compileString(Node $body, ArrayExpression $vars, bool $ignoreSt
if ('count' === $var && $this->hasNode('count')) {
$vars->addElement($this->getNode('count'), $key);
} else {
$varExpr = class_exists(ContextVariable::class) ? new ContextVariable($var, $body->getTemplateLine()) : new NameExpression($var, $body->getTemplateLine());
$varExpr = new ContextVariable($var, $body->getTemplateLine());
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
$vars->addElement($varExpr, $key);
}
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ private function createCommandTester(): CommandTester
private function createCommand(): Command
{
$environment = new Environment(new FilesystemLoader(\dirname(__DIR__).'/Fixtures/templates/'));
if (class_exists(DeprecatedCallableInfo::class)) {
$options = ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.1')];
} else {
$options = ['deprecated' => true];
}
$options = ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.1')];
$environment->addFilter(new TwigFilter('deprecated_filter', fn ($v) => $v, $options));

$command = new LintCommand($environment);
Expand Down
30 changes: 7 additions & 23 deletions src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
use Twig\Compiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Node;
use Twig\Node\Nodes;

class DumpNodeTest extends TestCase
Expand Down Expand Up @@ -73,15 +71,9 @@ public function testIndented()

public function testOneVar()
{
if (class_exists(Nodes::class)) {
$vars = new Nodes([
new ContextVariable('foo', 7),
]);
} else {
$vars = new Node([
new NameExpression('foo', 7),
]);
}
$vars = new Nodes([
new ContextVariable('foo', 7),
]);

$node = new DumpNode('bar', $vars, 7);

Expand All @@ -103,18 +95,10 @@ public function testOneVar()

public function testMultiVars()
{
if (class_exists(Nodes::class)) {
$vars = new Nodes([
new ContextVariable('foo', 7),
new ContextVariable('bar', 7),
]);
} else {
$vars = new Node([
new NameExpression('foo', 7),
new NameExpression('bar', 7),
]);
}

$vars = new Nodes([
new ContextVariable('foo', 7),
new ContextVariable('bar', 7),
]);
$node = new DumpNode('bar', $vars, 7);

$env = new Environment($this->createMock(LoaderInterface::class));
Expand Down
21 changes: 6 additions & 15 deletions src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Node;
use Twig\Node\Nodes;

class FormThemeTest extends TestCase
Expand All @@ -32,18 +30,11 @@ class FormThemeTest extends TestCase

public function testConstructor()
{
$form = class_exists(ContextVariable::class) ? new ContextVariable('form', 0) : new NameExpression('form', 0);
if (class_exists(Nodes::class)) {
$resources = new Nodes([
new ConstantExpression('tpl1', 0),
new ConstantExpression('tpl2', 0),
]);
} else {
$resources = new Node([
new ConstantExpression('tpl1', 0),
new ConstantExpression('tpl2', 0),
]);
}
$form = new ContextVariable('form', 0);
$resources = new Nodes([
new ConstantExpression('tpl1', 0),
new ConstantExpression('tpl2', 0),
]);

$node = new FormThemeNode($form, $resources, 0);

Expand All @@ -54,7 +45,7 @@ public function testConstructor()

public function testCompile()
{
$form = class_exists(ContextVariable::class) ? new ContextVariable('form', 0) : new NameExpression('form', 0);
$form = new ContextVariable('form', 0);
$resources = new ArrayExpression([
new ConstantExpression(1, 0),
new ConstantExpression('tpl1', 0),
Expand Down
61 changes: 18 additions & 43 deletions src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Twig\Extension\CoreExtension;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConditionalExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\Ternary\ConditionalTernary;
use Twig\Node\Expression\Variable\ContextVariable;
Expand Down Expand Up @@ -207,27 +206,15 @@ public function testCompileLabelWithLabelAndAttributes()

public function testCompileLabelWithLabelThatEvaluatesToNull()
{
if (class_exists(ConditionalTernary::class)) {
$conditional = new ConditionalTernary(
// if
new ConstantExpression(true, 0),
// then
new ConstantExpression(null, 0),
// else
new ConstantExpression(null, 0),
0
);
} else {
$conditional = new ConditionalExpression(
// if
new ConstantExpression(true, 0),
// then
new ConstantExpression(null, 0),
// else
new ConstantExpression(null, 0),
0
);
}
$conditional = new ConditionalTernary(
// if
new ConstantExpression(true, 0),
// then
new ConstantExpression(null, 0),
// else
new ConstantExpression(null, 0),
0
);

$arguments = new Nodes([new ContextVariable('form', 0), $conditional]);

Expand All @@ -250,27 +237,15 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()

public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
{
if (class_exists(ConditionalTernary::class)) {
$conditional = new ConditionalTernary(
// if
new ConstantExpression(true, 0),
// then
new ConstantExpression(null, 0),
// else
new ConstantExpression(null, 0),
0
);
} else {
$conditional = new ConditionalExpression(
// if
new ConstantExpression(true, 0),
// then
new ConstantExpression(null, 0),
// else
new ConstantExpression(null, 0),
0
);
}
$conditional = new ConditionalTernary(
// if
new ConstantExpression(true, 0),
// then
new ConstantExpression(null, 0),
// else
new ConstantExpression(null, 0),
0
);

$arguments = new Nodes([
new ContextVariable('form', 0),
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Twig\Compiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\TextNode;

Expand All @@ -28,7 +27,7 @@ class TransNodeTest extends TestCase
public function testCompileStrict()
{
$body = new TextNode('trans %var%', 0);
$vars = class_exists(ContextVariable::class) ? new ContextVariable('foo', 0) : new NameExpression('foo', 0);
$vars = new ContextVariable('foo', 0);
$node = new TransNode($body, null, null, $vars);

$env = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Node;
use Twig\Node\Nodes;
Expand All @@ -41,17 +40,10 @@ public function testMessageExtractionWithInvalidDomainNode()
{
$message = 'new key';

if (class_exists(Nodes::class)) {
$n = new Nodes([
new ArrayExpression([], 0),
new ContextVariable('variable', 0),
]);
} else {
$n = new Node([
new ArrayExpression([], 0),
new NameExpression('variable', 0),
]);
}
$n = new Nodes([
new ArrayExpression([], 0),
new ContextVariable('variable', 0),
]);

$node = new FilterExpression(
new ConstantExpression($message, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function parse(Token $token): Node
}
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

return new DumpNode(class_exists(LocalVariable::class) ? new LocalVariable(null, $token->getLine()) : $this->parser->getVarName(), $values, $token->getLine(), $this->getTag());
return new DumpNode(new LocalVariable(null, $token->getLine()), $values, $token->getLine());
}

private function parseMultitargetExpression(): Node
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bridge\Twig\TokenParser;

use Symfony\Bridge\Twig\Node\StopwatchNode;
use Twig\Node\Expression\AssignNameExpression;
use Twig\Node\Expression\Variable\LocalVariable;
use Twig\Node\Node;
use Twig\Token;
Expand Down Expand Up @@ -45,7 +44,7 @@ public function parse(Token $token): Node
$stream->expect(Token::BLOCK_END_TYPE);

if ($this->stopwatchIsAvailable) {
return new StopwatchNode($name, $body, class_exists(LocalVariable::class) ? new LocalVariable(null, $token->getLine()) : new AssignNameExpression($this->parser->getVarName(), $token->getLine()), $lineno, $this->getTag());
return new StopwatchNode($name, $body, new LocalVariable(null, $token->getLine()), $lineno);
}

return $body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function parse(Token $token): Node

$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

return new TransDefaultDomainNode($expr, $token->getLine(), $this->getTag());
return new TransDefaultDomainNode($expr, $token->getLine());
}

public function getTag(): string
Expand Down
Loading
0