1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 19:54:12 +02:00

[ticket/16654] Upgrade Twig to version 3

PHPBB3-16654
This commit is contained in:
rxu
2020-12-01 13:10:45 +07:00
parent 382c7acbc8
commit 1d9f9b5ecd
14 changed files with 83 additions and 79 deletions

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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);
}
/**

View File

@@ -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")
;
}

View File

@@ -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('===');
}

View File

@@ -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('!==');
}

View File

@@ -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);

View File

@@ -41,7 +41,7 @@ class defineparser extends \Twig\TokenParser\AbstractTokenParser
{
// This would happen if someone improperly formed their DEFINE syntax
// e.g. <!-- DEFINE $VAR = foo -->
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);

View File

@@ -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';
}