From 24e9cf215590d1090b3d4acbf07e1fb44a973ca8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Sep 2016 11:43:20 -0700 Subject: [PATCH] fixed Twig support for 1.26 and 2.0 --- composer.json | 2 +- .../Bridge/Twig/Node/FormThemeNode.php | 2 +- .../Bridge/Twig/Node/RenderBlockNode.php | 2 +- .../Twig/Node/SearchAndRenderBlockNode.php | 2 +- .../Bridge/Twig/Node/StopwatchNode.php | 4 ++-- src/Symfony/Bridge/Twig/Node/TransNode.php | 2 +- .../Bridge/Twig/Tests/Node/FormThemeTest.php | 4 ++-- .../Node/SearchAndRenderBlockNodeTest.php | 20 +++++++++---------- .../Bridge/Twig/Tests/Node/TransNodeTest.php | 2 +- .../Bridge/Twig/Translation/TwigExtractor.php | 2 +- src/Symfony/Bridge/Twig/composer.json | 2 +- .../Bundle/SecurityBundle/composer.json | 2 +- .../Configurator/EnvironmentConfigurator.php | 6 +++--- .../Bundle/TwigBundle/Node/RenderNode.php | 2 +- src/Symfony/Bundle/TwigBundle/TwigEngine.php | 2 +- src/Symfony/Bundle/TwigBundle/composer.json | 1 + 16 files changed, 29 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 05e9d158ae..468b4f5b26 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "paragonie/random_compat": "~1.0", "symfony/polyfill-apcu": "~1.1", "symfony/polyfill-mbstring": "~1.1", - "twig/twig": "~1.23|~2.0", + "twig/twig": "~1.26|~2.0", "psr/log": "~1.0" }, "replace": { diff --git a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php index e598ae104a..9179377139 100644 --- a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php +++ b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php @@ -30,7 +30,7 @@ class FormThemeNode extends \Twig_Node { $compiler ->addDebugInfo($this) - ->write('$this->env->getExtension(\'form\')->renderer->setTheme(') + ->write('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->setTheme(') ->subcompile($this->getNode('form')) ->raw(', ') ->subcompile($this->getNode('resources')) diff --git a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php index 35dcb40b62..33865e2f1c 100644 --- a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php +++ b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php @@ -25,7 +25,7 @@ class RenderBlockNode extends \Twig_Node_Expression_Function { $compiler->addDebugInfo($this); $arguments = iterator_to_array($this->getNode('arguments')); - $compiler->write('$this->env->getExtension(\'form\')->renderer->renderBlock('); + $compiler->write('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->renderBlock('); if (isset($arguments[0])) { $compiler->subcompile($arguments[0]); diff --git a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php index 93bba43b4c..8c42bcd3c2 100644 --- a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php +++ b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php @@ -19,7 +19,7 @@ class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this); - $compiler->raw('$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock('); + $compiler->raw('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock('); preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches); diff --git a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php index 839e3f7698..95d755a78c 100644 --- a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php +++ b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php @@ -32,11 +32,11 @@ class StopwatchNode extends \Twig_Node ->raw(' = ') ->subcompile($this->getNode('name')) ->write(";\n") - ->write("\$this->env->getExtension('stopwatch')->getStopwatch()->start(") + ->write("\$this->env->getExtension('Symfony\Bridge\Twig\Extension\StopwatchExtension')->getStopwatch()->start(") ->subcompile($this->getNode('var')) ->raw(", 'template');\n") ->subcompile($this->getNode('body')) - ->write("\$this->env->getExtension('stopwatch')->getStopwatch()->stop(") + ->write("\$this->env->getExtension('Symfony\Bridge\Twig\Extension\StopwatchExtension')->getStopwatch()->stop(") ->subcompile($this->getNode('var')) ->raw(");\n") ; diff --git a/src/Symfony/Bridge/Twig/Node/TransNode.php b/src/Symfony/Bridge/Twig/Node/TransNode.php index 5f1915d05e..114b38c441 100644 --- a/src/Symfony/Bridge/Twig/Node/TransNode.php +++ b/src/Symfony/Bridge/Twig/Node/TransNode.php @@ -54,7 +54,7 @@ class TransNode extends \Twig_Node $method = !$this->hasNode('count') ? 'trans' : 'transChoice'; $compiler - ->write('echo $this->env->getExtension(\'translator\')->getTranslator()->'.$method.'(') + ->write('echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->getTranslator()->'.$method.'(') ->subcompile($msg) ; diff --git a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php index 0fadfdabc6..f407afdcd6 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php @@ -45,7 +45,7 @@ class FormThemeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"));', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"));', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -57,7 +57,7 @@ class FormThemeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->setTheme(%s, "tpl1");', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->setTheme(%s, "tpl1");', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) diff --git a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php index 05b28c947d..ad76e25e8e 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php @@ -27,7 +27,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\')', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'widget\')', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -50,7 +50,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\', array("foo" => "bar"))', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'widget\', array("foo" => "bar"))', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -70,7 +70,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("label" => "my label"))', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\', array("label" => "my label"))', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -92,7 +92,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase // Otherwise the default label is overwritten with null. $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\')', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -114,7 +114,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase // Otherwise the default label is overwritten with null. $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\')', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -133,7 +133,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\')', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -160,7 +160,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase // https://github.com/symfony/symfony/issues/5029 $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar"))', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar"))', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -186,7 +186,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in argument"))', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in argument"))', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -217,7 +217,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase // https://github.com/symfony/symfony/issues/5029 $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) @@ -254,7 +254,7 @@ class SearchAndRenderBlockNodeTest extends \PHPUnit_Framework_TestCase // https://github.com/symfony/symfony/issues/5029 $this->assertEquals( sprintf( - '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in attributes") + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))', + '$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in attributes") + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))', $this->getVariableGetter('form') ), trim($compiler->compile($node)->getSource()) diff --git a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php index 26ba94a1bf..032975a8f2 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php @@ -29,7 +29,7 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase $this->assertEquals( sprintf( - 'echo $this->env->getExtension(\'translator\')->getTranslator()->trans("trans %%var%%", array_merge(array("%%var%%" => %s), %s), "messages");', + 'echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->getTranslator()->trans("trans %%var%%", array_merge(array("%%var%%" => %s), %s), "messages");', $this->getVariableGetterWithoutStrictCheck('var'), $this->getVariableGetterWithStrictCheck('foo') ), diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index d892fe7303..2a9450c885 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -82,7 +82,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface protected function extractTemplate($template, MessageCatalogue $catalogue) { - $visitor = $this->twig->getExtension('translator')->getTranslationNodeVisitor(); + $visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor(); $visitor->enable(); $this->twig->parse($this->twig->tokenize($template)); diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index f62708cf97..c82e7b8cf4 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.3.9", - "twig/twig": "~1.23|~2.0" + "twig/twig": "~1.26|~2.0" }, "require-dev": { "symfony/asset": "~2.7", diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index f00e09ca3c..0ca847bc1b 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -37,7 +37,7 @@ "symfony/yaml": "~2.0,>=2.0.5", "symfony/expression-language": "~2.6", "doctrine/doctrine-bundle": "~1.2", - "twig/twig": "~1.23|~2.0", + "twig/twig": "~1.26|~2.0", "ircmaxell/password-compat": "~1.0" }, "autoload": { diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php index 21e9a1a25c..bf37559b99 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php @@ -37,12 +37,12 @@ class EnvironmentConfigurator public function configure(\Twig_Environment $environment) { - $environment->getExtension('core')->setDateFormat($this->dateFormat, $this->intervalFormat); + $environment->getExtension('Twig_Extension_Core')->setDateFormat($this->dateFormat, $this->intervalFormat); if (null !== $this->timezone) { - $environment->getExtension('core')->setTimezone($this->timezone); + $environment->getExtension('Twig_Extension_Core')->setTimezone($this->timezone); } - $environment->getExtension('core')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator); + $environment->getExtension('Twig_Extension_Core')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator); } } diff --git a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php b/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php index 1c590f9ac8..4e3b12dae1 100644 --- a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php +++ b/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php @@ -34,7 +34,7 @@ class RenderNode extends \Twig_Node { $compiler ->addDebugInfo($this) - ->write("echo \$this->env->getExtension('actions')->renderUri(") + ->write("echo \$this->env->getExtension('Symfony\Bundle\TwigBundle\Extension\ActionsExtension')->renderUri(") ->subcompile($this->getNode('expr')) ->raw(', ') ->subcompile($this->getNode('options')) diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index 5cd666a317..3092fe9c5d 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -49,7 +49,7 @@ class TwigEngine extends BaseEngine implements EngineInterface { @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Inject the escaping strategy in the Twig_Environment object instead.', E_USER_DEPRECATED); - $this->environment->getExtension('escaper')->setDefaultStrategy($strategy); + $this->environment->getExtension('Twig_Extension_Escaper')->setDefaultStrategy($strategy); } /** diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index c05ebe38e8..7892f38cd4 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -19,6 +19,7 @@ "php": ">=5.3.9", "symfony/asset": "~2.7", "symfony/twig-bridge": "~2.7", + "twig/twig": "~1.26|~2.0", "symfony/http-foundation": "~2.5", "symfony/http-kernel": "~2.7" },