Skip to content

Commit 2848f7d

Browse files
committed
allow Twig 4
1 parent cc11de0 commit 2848f7d

File tree

10 files changed

+15
-10
lines changed

10 files changed

+15
-10
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"ext-xml": "*",
4040
"doctrine/event-manager": "^2",
4141
"doctrine/persistence": "^3.1",
42-
"twig/twig": "^3.12",
42+
"twig/twig": "^3.12|^4.0",
4343
"psr/cache": "^2.0|^3.0",
4444
"psr/clock": "^1.0",
4545
"psr/container": "^1.1|^2.0",

src/Symfony/Bridge/Twig/Command/DebugCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function displayGeneralText(SymfonyStyle $io, ?string $filter = null): v
218218
$types = ['functions', 'filters', 'tests', 'globals'];
219219
foreach ($types as $index => $type) {
220220
$items = [];
221-
foreach ($this->twig->{'get'.ucfirst($type)}() as $name => $entity) {
221+
foreach ((new \ReflectionMethod(Environment::class, 'get' . ucfirst($type)))->invoke($this->twig) as $name => $entity) {
222222
if (!$filter || str_contains($name, $filter)) {
223223
$items[$name] = $name.$this->getPrettyMetadata($type, $entity, $decorated);
224224
}
@@ -252,7 +252,7 @@ private function displayGeneralJson(SymfonyStyle $io, ?string $filter): void
252252
$types = ['functions', 'filters', 'tests', 'globals'];
253253
$data = [];
254254
foreach ($types as $type) {
255-
foreach ($this->twig->{'get'.ucfirst($type)}() as $name => $entity) {
255+
foreach ((new \ReflectionMethod(Environment::class, 'get' . ucfirst($type)))->invoke($this->twig) as $name => $entity) {
256256
if (!$filter || str_contains($name, $filter)) {
257257
$data[$type][$name] = $this->getMetadata($type, $entity);
258258
}

src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Twig\Loader\LoaderInterface;
1919
use Twig\Node\Expression\NameExpression;
2020
use Twig\Node\TextNode;
21+
use Twig\Runtime\LoopIterator;
2122

2223
/**
2324
* @author Asmir Mustafic <goetas@gmail.com>
@@ -50,6 +51,10 @@ protected function getVariableGetterWithoutStrictCheck($name)
5051

5152
protected function getVariableGetterWithStrictCheck($name)
5253
{
54+
if (class_exists(LoopIterator::class)) {
55+
return \sprintf('(array_key_exists("%1$s", $context) ? $context["%1$s"] : throw new RuntimeError(\'Variable "%1$s" does not exist.\', 0, $this->source))', $name);
56+
}
57+
5358
return \sprintf('(isset($context["%1$s"]) || array_key_exists("%1$s", $context) ? $context["%1$s"] : (function () { throw new RuntimeError(\'Variable "%1$s" does not exist.\', 0, $this->source); })())', $name);
5459
}
5560
}

src/Symfony/Bridge/Twig/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=8.2",
2020
"symfony/deprecation-contracts": "^2.5|^3",
2121
"symfony/translation-contracts": "^2.5|^3",
22-
"twig/twig": "^3.12"
22+
"twig/twig": "^3.12|^4.0"
2323
},
2424
"require-dev": {
2525
"egulias/email-validator": "^2.1.10|^3|^4",

src/Symfony/Bundle/FrameworkBundle/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"symfony/web-link": "^6.4|^7.0",
7474
"symfony/webhook": "^7.2",
7575
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
76-
"twig/twig": "^3.12"
76+
"twig/twig": "^3.12|^4.0"
7777
},
7878
"conflict": {
7979
"doctrine/persistence": "<1.3",

src/Symfony/Bundle/SecurityBundle/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"symfony/twig-bridge": "^6.4|^7.0",
5151
"symfony/validator": "^6.4|^7.0",
5252
"symfony/yaml": "^6.4|^7.0",
53-
"twig/twig": "^3.12",
53+
"twig/twig": "^3.12|^4.0",
5454
"web-token/jwt-library": "^3.3.2|^4.0"
5555
},
5656
"conflict": {

src/Symfony/Bundle/TwigBundle/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/twig-bridge": "^6.4|^7.0",
2424
"symfony/http-foundation": "^6.4|^7.0",
2525
"symfony/http-kernel": "^6.4|^7.0",
26-
"twig/twig": "^3.12"
26+
"twig/twig": "^3.12|^4.0"
2727
},
2828
"require-dev": {
2929
"symfony/asset": "^6.4|^7.0",

src/Symfony/Bundle/WebProfilerBundle/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/http-kernel": "^6.4|^7.0",
2323
"symfony/routing": "^6.4|^7.0",
2424
"symfony/twig-bundle": "^6.4|^7.0",
25-
"twig/twig": "^3.12"
25+
"twig/twig": "^3.12|^4.0"
2626
},
2727
"require-dev": {
2828
"symfony/browser-kit": "^6.4|^7.0",

src/Symfony/Component/HttpKernel/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"symfony/var-dumper": "^6.4|^7.0",
4848
"symfony/var-exporter": "^6.4|^7.0",
4949
"psr/cache": "^1.0|^2.0|^3.0",
50-
"twig/twig": "^3.12"
50+
"twig/twig": "^3.12|^4.0"
5151
},
5252
"provide": {
5353
"psr/log-implementation": "1.0|2.0|3.0"

src/Symfony/Component/VarDumper/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/http-kernel": "^6.4|^7.0",
2626
"symfony/process": "^6.4|^7.0",
2727
"symfony/uid": "^6.4|^7.0",
28-
"twig/twig": "^3.12"
28+
"twig/twig": "^3.12|^4.0"
2929
},
3030
"conflict": {
3131
"symfony/console": "<6.4"

0 commit comments

Comments
 (0)