From 1d9f9b5ecd5d3801fb058f63335aa869dd01c7b6 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 1 Dec 2020 13:10:45 +0700 Subject: [PATCH] [ticket/16654] Upgrade Twig to version 3 PHPBB3-16654 --- phpBB/adm/style/acp_storage.html | 82 ++++++++++--------- phpBB/composer.json | 2 +- phpBB/composer.lock | 35 ++++---- phpBB/phpbb/template/twig/environment.php | 13 +-- phpBB/phpbb/template/twig/lexer.php | 2 +- phpBB/phpbb/template/twig/loader.php | 4 +- phpBB/phpbb/template/twig/node/event.php | 2 +- .../node/expression/binary/equalequal.php | 2 +- .../node/expression/binary/notequalequal.php | 2 +- .../phpbb/template/twig/node/includenode.php | 2 +- .../twig/tokenparser/defineparser.php | 2 +- .../twig/tokenparser/includeparser.php | 4 +- .../template/ucp_pm_viewmessage.html | 4 +- tests/template/template_test.php | 6 +- 14 files changed, 83 insertions(+), 79 deletions(-) diff --git a/phpBB/adm/style/acp_storage.html b/phpBB/adm/style/acp_storage.html index 51a1d9b15f..3886f006d1 100644 --- a/phpBB/adm/style/acp_storage.html +++ b/phpBB/adm/style/acp_storage.html @@ -43,53 +43,57 @@

{{ lang('STORAGE_SELECT_DESC') }}
- {% for provider in PROVIDERS if provider.is_available %} -
- {{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }} - {% for name, options in provider.get_options %} - {% set title = 'STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_OPTION_' ~ name | upper %} - {% set description = 'STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_OPTION_' ~ name | upper ~ '_EXPLAIN' %} - {% set input_id = storage.get_name ~ '_' ~ provider.get_name ~ '_' ~ name %} - {% set input_type = options['type'] %} - {% set input_name = storage.get_name ~ '[' ~ name ~ ']' %} - {% set input_value = attribute(config, 'storage\\' ~ storage.get_name ~ '\\config\\' ~ name) %} -
-
- - {% if lang_defined(description) %} -
{{ lang(description) }} - {% endif %} -
-
- {% if input_type in ['text', 'password', 'email'] %} - - {% elseif input_type == 'textarea' %} - - {% elseif input_type == 'radio' %} - {% for option_name, option_value in options['options'] %} - {{ lang(option_name) }} - {% endfor %} - {% elseif input_type == 'select' %} - + {% elseif input_type == 'textarea' %} + + {% elseif input_type == 'radio' %} {% for option_name, option_value in options['options'] %} - + {{ lang(option_name) }} {% endfor %} - - {% endif %} -
-
- {% endfor %} -
+ {% elseif input_type == 'select' %} + + {% endif %} + + + {% endfor %} + + {% endif %} {% endfor %} {% endfor %} diff --git a/phpBB/composer.json b/phpBB/composer.json index 93922b7609..0d0330c318 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -56,7 +56,7 @@ "symfony/routing": "~5.2", "symfony/twig-bridge": "~5.2", "symfony/yaml": "~5.2", - "twig/twig": "^1.0 || ^2.0" + "twig/twig": "^3.0" }, "require-dev": { "fabpot/goutte": "~3.2", diff --git a/phpBB/composer.lock b/phpBB/composer.lock index af80be5029..7fda0639ee 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f33ff5b8d67189b9b8c2bf749f8fd4e0", + "content-hash": "8b28fd874f1be23586736a9c2155f5c4", "packages": [ { "name": "bantu/ini-get-wrapper", @@ -1553,24 +1553,26 @@ }, { "name": "laminas/laminas-zendframework-bridge", - "version": "1.1.1", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-zendframework-bridge.git", - "reference": "6ede70583e101030bcace4dcddd648f760ddf642" + "reference": "6cccbddfcfc742eb02158d6137ca5687d92cee32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/6ede70583e101030bcace4dcddd648f760ddf642", - "reference": "6ede70583e101030bcace4dcddd648f760ddf642", + "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/6cccbddfcfc742eb02158d6137ca5687d92cee32", + "reference": "6cccbddfcfc742eb02158d6137ca5687d92cee32", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0 || ^8.0" + "php": "^7.3 || ^8.0" }, "require-dev": { "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.1 || ^9.3", - "squizlabs/php_codesniffer": "^3.5" + "psalm/plugin-phpunit": "^0.15.1", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.6" }, "type": "library", "extra": { @@ -1609,7 +1611,7 @@ "type": "community_bridge" } ], - "time": "2020-09-14T14:23:00+00:00" + "time": "2021-02-25T21:54:58+00:00" }, { "name": "lusitanian/oauth", @@ -4883,16 +4885,16 @@ }, { "name": "twig/twig", - "version": "v2.14.3", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "8bc568d460d88b25c00c046256ec14a787ea60d9" + "reference": "1f3b7e2c06cc05d42936a8ad508ff1db7975cdc5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/8bc568d460d88b25c00c046256ec14a787ea60d9", - "reference": "8bc568d460d88b25c00c046256ec14a787ea60d9", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/1f3b7e2c06cc05d42936a8ad508ff1db7975cdc5", + "reference": "1f3b7e2c06cc05d42936a8ad508ff1db7975cdc5", "shasum": "" }, "require": { @@ -4907,13 +4909,10 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.14-dev" + "dev-master": "3.3-dev" } }, "autoload": { - "psr-0": { - "Twig_": "lib/" - }, "psr-4": { "Twig\\": "src/" } @@ -4946,7 +4945,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v2.14.3" + "source": "https://github.com/twigphp/Twig/tree/v3.3.0" }, "funding": [ { @@ -4958,7 +4957,7 @@ "type": "tidelift" } ], - "time": "2021-01-05T15:34:33+00:00" + "time": "2021-02-08T09:54:36+00:00" } ], "packages-dev": [ diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 27426606aa..bcffbd06ce 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -181,7 +181,7 @@ class environment extends \Twig\Environment /** * {@inheritdoc} */ - public function render($name, array $context = []) + public function render($name, array $context = []) : string { return $this->display_with_assets($name, $context); } @@ -189,7 +189,7 @@ class environment extends \Twig\Environment /** * {@inheritdoc} */ - public function display($name, array $context = []) + public function display($name, array $context = []) : void { echo $this->display_with_assets($name, $context); } @@ -259,12 +259,13 @@ class environment extends \Twig\Environment /** * Loads a template by name. * + * @param string $cls The template class associated with the given template name * @param string $name The template name * @param integer $index The index if it is an embedded template * @return \Twig\Template A template instance representing the given template name * @throws \Twig\Error\LoaderError */ - public function loadTemplate($name, $index = null) + public function loadTemplate(string $cls, string $name, int $index = null) : \Twig\Template { if (strpos($name, '@') === false) { @@ -274,10 +275,10 @@ class environment extends \Twig\Environment { if ($namespace === '__main__') { - return parent::loadTemplate($name, $index); + return parent::loadTemplate($cls, $name, $index); } - return parent::loadTemplate('@' . $namespace . '/' . $name, $index); + return parent::loadTemplate($this->getTemplateClass('@' . $namespace . '/' . $name), '@' . $namespace . '/' . $name, $index); } catch (\Twig\Error\LoaderError $e) { @@ -289,7 +290,7 @@ class environment extends \Twig\Environment } else { - return parent::loadTemplate($name, $index); + return parent::loadTemplate($cls, $name, $index); } } diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index a8424f6f73..d5ab8e768a 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -15,7 +15,7 @@ namespace phpbb\template\twig; class lexer extends \Twig\Lexer { - public function tokenize(\Twig\Source $source) + public function tokenize(\Twig\Source $source) : \Twig\TokenStream { $code = $source->getCode(); $filename = $source->getName(); diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index 1e0b2d1520..39bb0458a3 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -99,9 +99,9 @@ class loader extends \Twig\Loader\FilesystemLoader * * {@inheritdoc} */ - public function addPath($path, $namespace = self::MAIN_NAMESPACE) + public function addPath($path, $namespace = self::MAIN_NAMESPACE) : void { - return parent::addPath(filesystem_helper::realpath($path), $namespace); + parent::addPath(filesystem_helper::realpath($path), $namespace); } /** diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php index 9766750500..76bfc6d127 100644 --- a/phpBB/phpbb/template/twig/node/event.php +++ b/phpBB/phpbb/template/twig/node/event.php @@ -65,7 +65,7 @@ class event extends \Twig\Node\Node // We set the namespace lookup order to be this extension first, then the main path ->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n") - ->write("\$this->env->loadTemplate('@{$ext_namespace}/{$location}.html')->display(\$context);\n") + ->write("\$this->env->loadTemplate(\$this->env->getTemplateClass('@{$ext_namespace}/{$location}.html'), '@{$ext_namespace}/{$location}.html')->display(\$context);\n") ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") ; } diff --git a/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php index cf11b2876d..46a40fc08a 100644 --- a/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php +++ b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php @@ -15,7 +15,7 @@ namespace phpbb\template\twig\node\expression\binary; class equalequal extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(\Twig\Compiler $compiler) : \Twig\Compiler { return $compiler->raw('==='); } diff --git a/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php index c8b0ac98e8..dc1d210b4b 100644 --- a/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php +++ b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php @@ -15,7 +15,7 @@ namespace phpbb\template\twig\node\expression\binary; class notequalequal extends \Twig\Node\Expression\Binary\AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(\Twig\Compiler $compiler) : \Twig\Compiler { return $compiler->raw('!=='); } diff --git a/phpBB/phpbb/template/twig/node/includenode.php b/phpBB/phpbb/template/twig/node/includenode.php index 1786b3a430..25996a712e 100644 --- a/phpBB/phpbb/template/twig/node/includenode.php +++ b/phpBB/phpbb/template/twig/node/includenode.php @@ -20,7 +20,7 @@ class includenode extends \Twig\Node\IncludeNode * * @param \Twig\Compiler A Twig\Compiler instance */ - public function compile(\Twig\Compiler $compiler) + public function compile(\Twig\Compiler $compiler) : void { $compiler->addDebugInfo($this); diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index 3cb7873652..ac98dce421 100644 --- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -41,7 +41,7 @@ class defineparser extends \Twig\TokenParser\AbstractTokenParser { // This would happen if someone improperly formed their DEFINE syntax // e.g. - throw new \Twig\Error\SyntaxError('Invalid DEFINE', $token->getLine(), $this->parser->getStream()->getSourceContext()->getPath()); + throw new \Twig\Error\SyntaxError('Invalid DEFINE', $token->getLine(), $this->parser->getStream()->getSourceContext()); } $stream->expect(\Twig\Token::BLOCK_END_TYPE); diff --git a/phpBB/phpbb/template/twig/tokenparser/includeparser.php b/phpBB/phpbb/template/twig/tokenparser/includeparser.php index 62148489fa..f06c41369c 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includeparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/includeparser.php @@ -23,7 +23,7 @@ class includeparser extends \Twig\TokenParser\IncludeTokenParser * * @return \Twig\Node\Node A Twig\Node instance */ - public function parse(\Twig\Token $token) + public function parse(\Twig\Token $token) : \Twig\Node\Node { $expr = $this->parser->getExpressionParser()->parseExpression(); @@ -37,7 +37,7 @@ class includeparser extends \Twig\TokenParser\IncludeTokenParser * * @return string The tag name */ - public function getTag() + public function getTag() : string { return 'INCLUDE'; } diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html b/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html index 6e80673588..f0e5aabcf1 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html +++ b/phpBB/styles/prosilver/template/ucp_pm_viewmessage.html @@ -32,12 +32,12 @@ {AUTHOR_AVATAR} - {% spaceless %} + {% apply spaceless %} {% EVENT ucp_pm_viewmessage_author_full_before %} {MESSAGE_AUTHOR_FULL} {% EVENT ucp_pm_viewmessage_author_full_after %} {{ Icon('iconify', 'fa:circle', lang('ONLINE'), true, 'c-online-icon') }} - {% endspaceless %} + {% endapply %} diff --git a/tests/template/template_test.php b/tests/template/template_test.php index fa84cb9770..e6e3fda5f2 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -522,7 +522,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->template->set_filenames(array('test' => $filename)); $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); - $this->expectException('Twig_Error_Loader'); + $this->expectException(\Twig\Error\LoaderError::class); $this->display('test'); } @@ -530,7 +530,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case public function test_invalid_handle() { - $this->expectException('Twig_Error_Loader'); + $this->expectException(\Twig\Error\LoaderError::class); $this->display('test'); } @@ -1076,7 +1076,7 @@ EOT public function test_define_error() { - $this->expectException('Twig_Error_Syntax'); + $this->expectException(\Twig\Error\SyntaxError::class); $this->run_template('define_error.html', array(), array(), array(), ''); } }