From 09f4eb5cd8babdaba8b9a2506d25dd8ca86f1133 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 20 Sep 2019 14:46:07 +0200 Subject: [PATCH] Allow Twig 3 --- composer.json | 2 +- src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php | 6 ++++++ src/Symfony/Bridge/Twig/Node/DumpNode.php | 2 +- src/Symfony/Bridge/Twig/Node/FormThemeNode.php | 3 +++ src/Symfony/Bridge/Twig/Node/RenderBlockNode.php | 3 +++ src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php | 3 +++ src/Symfony/Bridge/Twig/Node/StopwatchNode.php | 3 +++ src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php | 3 +++ src/Symfony/Bridge/Twig/Node/TransNode.php | 3 +++ .../Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php | 6 ++++++ .../Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php | 3 +++ src/Symfony/Bridge/Twig/composer.json | 2 +- src/Symfony/Bundle/FrameworkBundle/composer.json | 2 +- src/Symfony/Bundle/SecurityBundle/composer.json | 2 +- .../Bundle/TwigBundle/Loader/NativeFilesystemLoader.php | 2 ++ src/Symfony/Bundle/TwigBundle/composer.json | 2 +- .../Tests/Profiler/TemplateManagerTest.php | 2 ++ .../Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php | 6 ++++++ src/Symfony/Bundle/WebProfilerBundle/composer.json | 2 +- src/Symfony/Component/HttpKernel/composer.json | 2 +- src/Symfony/Component/VarDumper/composer.json | 2 +- 21 files changed, 52 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index bb539b5105..61b64b53d1 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "ext-xml": "*", "doctrine/event-manager": "~1.0", "doctrine/persistence": "~1.0", - "twig/twig": "^1.41|^2.10", + "twig/twig": "^1.41|^2.10|^3.0", "psr/cache": "~1.0", "psr/container": "^1.0", "psr/link": "^1.0", diff --git a/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php b/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php index 0d5d1d1fb3..a46f2cdbb8 100644 --- a/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php @@ -33,6 +33,9 @@ class ProfilerExtension extends BaseProfilerExtension $this->events = new \SplObjectStorage(); } + /** + * @return void + */ public function enter(Profile $profile) { if ($this->stopwatch && $profile->isTemplate()) { @@ -42,6 +45,9 @@ class ProfilerExtension extends BaseProfilerExtension parent::enter($profile); } + /** + * @return void + */ public function leave(Profile $profile) { parent::leave($profile); diff --git a/src/Symfony/Bridge/Twig/Node/DumpNode.php b/src/Symfony/Bridge/Twig/Node/DumpNode.php index c6f20ada89..d82d9ade1f 100644 --- a/src/Symfony/Bridge/Twig/Node/DumpNode.php +++ b/src/Symfony/Bridge/Twig/Node/DumpNode.php @@ -35,7 +35,7 @@ class DumpNode extends Node } /** - * {@inheritdoc} + * @return void */ public function compile(Compiler $compiler) { diff --git a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php index 0f07c8cbc6..b17243060f 100644 --- a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php +++ b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php @@ -27,6 +27,9 @@ class FormThemeNode extends Node parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno, $tag); } + /** + * @return void + */ public function compile(Compiler $compiler) { $compiler diff --git a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php index b4ba68cbef..29402a8024 100644 --- a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php +++ b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php @@ -26,6 +26,9 @@ use Twig\Node\Expression\FunctionExpression; */ class RenderBlockNode extends FunctionExpression { + /** + * @return void + */ public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); diff --git a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php index 7b29c3b36b..5a758ce9b0 100644 --- a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php +++ b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php @@ -23,6 +23,9 @@ use Twig\Node\Expression\FunctionExpression; */ class SearchAndRenderBlockNode extends FunctionExpression { + /** + * @return void + */ public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); diff --git a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php index 1d6094cdaf..b4dd8a9b37 100644 --- a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php +++ b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php @@ -29,6 +29,9 @@ class StopwatchNode extends Node parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag); } + /** + * @return void + */ public function compile(Compiler $compiler) { $compiler diff --git a/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php b/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php index 06dc00270d..49ceac1404 100644 --- a/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php +++ b/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php @@ -27,6 +27,9 @@ class TransDefaultDomainNode extends Node parent::__construct(['expr' => $expr], [], $lineno, $tag); } + /** + * @return void + */ public function compile(Compiler $compiler) { // noop as this node is just a marker for TranslationDefaultDomainNodeVisitor diff --git a/src/Symfony/Bridge/Twig/Node/TransNode.php b/src/Symfony/Bridge/Twig/Node/TransNode.php index 44f2b0ffbc..028047cff8 100644 --- a/src/Symfony/Bridge/Twig/Node/TransNode.php +++ b/src/Symfony/Bridge/Twig/Node/TransNode.php @@ -48,6 +48,9 @@ class TransNode extends Node parent::__construct($nodes, [], $lineno, $tag); } + /** + * @return void + */ public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php index 3279c2cbcc..a72697deb3 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php @@ -32,12 +32,18 @@ class TranslationNodeVisitor extends AbstractNodeVisitor private $enabled = false; private $messages = []; + /** + * @return void + */ public function enable() { $this->enabled = true; $this->messages = []; } + /** + * @return void + */ public function disable() { $this->enabled = false; diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php index 4cbc55b46a..8ee7830974 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php @@ -15,6 +15,9 @@ use Twig\Loader\FilesystemLoader; class StubFilesystemLoader extends FilesystemLoader { + /** + * @return string|null + */ protected function findTemplate($name, $throw = true) { // strip away bundle name diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index e299420c09..a8450f48db 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "symfony/translation-contracts": "^1.1|^2", - "twig/twig": "^1.41|^2.10" + "twig/twig": "^1.41|^2.10|^3.0" }, "require-dev": { "egulias/email-validator": "^2.1.10", diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 2ab4714b48..21c06c2394 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -60,7 +60,7 @@ "symfony/property-info": "^3.4|^4.0|^5.0", "symfony/web-link": "^4.4|^5.0", "phpdocumentor/reflection-docblock": "^3.0|^4.0", - "twig/twig": "~1.41|~2.10" + "twig/twig": "^1.41|^2.10|^3.0" }, "conflict": { "phpdocumentor/reflection-docblock": "<3.0", diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index a155930b4d..4bd0816938 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -44,7 +44,7 @@ "symfony/yaml": "^3.4|^4.0|^5.0", "symfony/expression-language": "^3.4|^4.0|^5.0", "doctrine/doctrine-bundle": "~1.5", - "twig/twig": "~1.41|~2.10" + "twig/twig": "^1.41|^2.10|^3.0" }, "conflict": { "symfony/browser-kit": "<4.2", diff --git a/src/Symfony/Bundle/TwigBundle/Loader/NativeFilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/NativeFilesystemLoader.php index 9ef58d7bdb..493fe25077 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/NativeFilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/NativeFilesystemLoader.php @@ -23,6 +23,8 @@ class NativeFilesystemLoader extends FilesystemLoader { /** * {@inheritdoc} + * + * @return string|null */ protected function findTemplate($template, $throw = true) { diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 5916b5d75f..c10735b578 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -22,7 +22,7 @@ "symfony/http-foundation": "^4.3|^5.0", "symfony/http-kernel": "^4.4", "symfony/polyfill-ctype": "~1.8", - "twig/twig": "~1.41|~2.10" + "twig/twig": "^1.41|^2.10|^3.0" }, "require-dev": { "symfony/asset": "^3.4|^4.0|^5.0", diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php index 5cdc50224c..de9ea03a4c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php @@ -15,6 +15,7 @@ use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager; use Symfony\Bundle\WebProfilerBundle\Tests\TestCase; use Symfony\Component\HttpKernel\Profiler\Profile; use Twig\Environment; +use Twig\Source; /** * Test for TemplateManager class. @@ -107,6 +108,7 @@ class TemplateManagerTest extends TestCase $loader = $this->getMockBuilder('Twig\Loader\SourceContextLoaderInterface')->getMock(); } else { $loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(); + $loader->method('getSourceContext')->willReturn(new Source('source-code', 'source-name')); } $this->twigEnvironment->expects($this->any())->method('getLoader')->willReturn($loader); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php index e7f80cba86..b13c13b109 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php @@ -48,11 +48,17 @@ class WebProfilerExtension extends ProfilerExtension $this->dumper->setOutput($this->output = fopen('php://memory', 'r+b')); } + /** + * @return void + */ public function enter(Profile $profile) { ++$this->stackLevel; } + /** + * @return void + */ public function leave(Profile $profile) { if (0 === --$this->stackLevel) { diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index d0cf3153cd..bb131bea9f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -23,7 +23,7 @@ "symfony/routing": "^3.4|^4.0|^5.0", "symfony/twig-bundle": "^4.2|^5.0", "symfony/var-dumper": "^3.4|^4.0|^5.0", - "twig/twig": "^1.41|^2.10" + "twig/twig": "^1.41|^2.10|^3.0" }, "require-dev": { "symfony/console": "^3.4|^4.0|^5.0", diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 2d7a6a9515..01b77c8665 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -42,7 +42,7 @@ "symfony/translation-contracts": "^1.1|^2", "symfony/var-dumper": "^4.1.1|^5.0", "psr/cache": "~1.0", - "twig/twig": "^1.34|^2.4" + "twig/twig": "^1.34|^2.4|^3.0" }, "provide": { "psr/log-implementation": "1.0" diff --git a/src/Symfony/Component/VarDumper/composer.json b/src/Symfony/Component/VarDumper/composer.json index 085efe4467..5225e8c463 100644 --- a/src/Symfony/Component/VarDumper/composer.json +++ b/src/Symfony/Component/VarDumper/composer.json @@ -24,7 +24,7 @@ "ext-iconv": "*", "symfony/console": "^3.4|^4.0|^5.0", "symfony/process": "^4.4|^5.0", - "twig/twig": "~1.34|~2.4" + "twig/twig": "^1.34|^2.4|^3.0" }, "conflict": { "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",