Support for Twig 3.

This commit is contained in:
Alexander M. Turek 2019-06-29 20:17:41 +02:00
parent 117acc3b02
commit f30edcab65
40 changed files with 85 additions and 115 deletions

View File

@ -20,7 +20,7 @@
"ext-xml": "*",
"doctrine/event-manager": "~1.0",
"doctrine/persistence": "~1.0",
"twig/twig": "^2.10",
"twig/twig": "^2.10|^3",
"psr/cache": "~1.0",
"psr/container": "^1.0",
"psr/link": "^1.0",

View File

@ -20,7 +20,7 @@ use Twig\TwigFunction;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class AssetExtension extends AbstractExtension
{
@ -36,7 +36,7 @@ class AssetExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('asset', [$this, 'getAssetUrl']),

View File

@ -20,7 +20,7 @@ use Twig\TwigFilter;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class CodeExtension extends AbstractExtension
{
@ -45,7 +45,7 @@ class CodeExtension extends AbstractExtension
*
* @return TwigFilter[]
*/
public function getFilters()
public function getFilters(): array
{
return [
new TwigFilter('abbr_class', [$this, 'abbrClass'], ['is_safe' => ['html']]),

View File

@ -18,7 +18,7 @@ use Twig\TwigFunction;
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
* @author Titouan Galopin <galopintitouan@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class CsrfExtension extends AbstractExtension
{

View File

@ -17,7 +17,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
* @author Titouan Galopin <galopintitouan@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class CsrfRuntime
{

View File

@ -25,7 +25,7 @@ use Twig\TwigFunction;
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final since Symfony 4.4
* @final
*/
class DumpExtension extends AbstractExtension
{
@ -41,7 +41,7 @@ class DumpExtension extends AbstractExtension
/**
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('dump', [$this, 'dump'], ['is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true]),
@ -51,7 +51,7 @@ class DumpExtension extends AbstractExtension
/**
* @return TokenParserInterface[]
*/
public function getTokenParsers()
public function getTokenParsers(): array
{
return [new DumpTokenParser()];
}

View File

@ -20,7 +20,7 @@ use Twig\TwigFunction;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class ExpressionExtension extends AbstractExtension
{
@ -29,7 +29,7 @@ class ExpressionExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('expression', [$this, 'createExpression']),

View File

@ -26,7 +26,7 @@ use Twig\TwigTest;
* @author Fabien Potencier <fabien@symfony.com>
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class FormExtension extends AbstractExtension
{
@ -35,7 +35,7 @@ class FormExtension extends AbstractExtension
*
* @return TokenParserInterface[]
*/
public function getTokenParsers()
public function getTokenParsers(): array
{
return [
// {% form_theme form "SomeBundle::widgets.twig" %}
@ -48,7 +48,7 @@ class FormExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('form_widget', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
@ -70,7 +70,7 @@ class FormExtension extends AbstractExtension
*
* @return TwigFilter[]
*/
public function getFilters()
public function getFilters(): array
{
return [
new TwigFilter('humanize', ['Symfony\Component\Form\FormRenderer', 'humanize']),
@ -83,7 +83,7 @@ class FormExtension extends AbstractExtension
*
* @return TwigTest[]
*/
public function getTests()
public function getTests(): array
{
return [
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),

View File

@ -21,7 +21,7 @@ use Twig\TwigFunction;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class HttpFoundationExtension extends AbstractExtension
{
@ -37,7 +37,7 @@ class HttpFoundationExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('absolute_url', [$this, 'generateAbsoluteUrl']),

View File

@ -20,14 +20,14 @@ use Twig\TwigFunction;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class HttpKernelExtension extends AbstractExtension
{
/**
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('render', [HttpKernelRuntime::class, 'renderFragment'], ['is_safe' => ['html']]),

View File

@ -19,7 +19,7 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class HttpKernelRuntime
{

View File

@ -20,7 +20,7 @@ use Twig\TwigFunction;
*
* @author Jeremy Mikola <jmikola@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class LogoutUrlExtension extends AbstractExtension
{
@ -36,7 +36,7 @@ class LogoutUrlExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('logout_url', [$this, 'getLogoutUrl']),

View File

@ -18,7 +18,7 @@ use Twig\Profiler\Profile;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class ProfilerExtension extends BaseProfilerExtension
{
@ -33,7 +33,7 @@ class ProfilerExtension extends BaseProfilerExtension
$this->events = new \SplObjectStorage();
}
public function enter(Profile $profile)
public function enter(Profile $profile): void
{
if ($this->stopwatch && $profile->isTemplate()) {
$this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
@ -42,7 +42,7 @@ class ProfilerExtension extends BaseProfilerExtension
parent::enter($profile);
}
public function leave(Profile $profile)
public function leave(Profile $profile): void
{
parent::leave($profile);

View File

@ -23,7 +23,7 @@ use Twig\TwigFunction;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class RoutingExtension extends AbstractExtension
{
@ -39,7 +39,7 @@ class RoutingExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('url', [$this, 'getUrl'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),

View File

@ -22,7 +22,7 @@ use Twig\TwigFunction;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class SecurityExtension extends AbstractExtension
{
@ -55,7 +55,7 @@ class SecurityExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('is_granted', [$this, 'isGranted']),

View File

@ -21,7 +21,7 @@ use Twig\TokenParser\TokenParserInterface;
*
* @author Wouter J <wouter@wouterj.nl>
*
* @final since Symfony 4.4
* @final
*/
class StopwatchExtension extends AbstractExtension
{
@ -42,7 +42,7 @@ class StopwatchExtension extends AbstractExtension
/**
* @return TokenParserInterface[]
*/
public function getTokenParsers()
public function getTokenParsers(): array
{
return [
/*

View File

@ -22,7 +22,7 @@ use Twig\TwigFunction;
*
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class WebLinkExtension extends AbstractExtension
{
@ -38,7 +38,7 @@ class WebLinkExtension extends AbstractExtension
*
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('link', [$this, 'link']),

View File

@ -22,7 +22,7 @@ use Twig\TwigFunction;
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @final since Symfony 4.4
* @final
*/
class WorkflowExtension extends AbstractExtension
{
@ -36,7 +36,7 @@ class WorkflowExtension extends AbstractExtension
/**
* @return TwigFunction[]
*/
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('workflow_can', [$this, 'canTransition']),

View File

@ -21,7 +21,7 @@ use Twig\TwigFilter;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class YamlExtension extends AbstractExtension
{
@ -30,7 +30,7 @@ class YamlExtension extends AbstractExtension
*
* @return TwigFilter[]
*/
public function getFilters()
public function getFilters(): array
{
return [
new TwigFilter('yaml_encode', [$this, 'encode']),

View File

@ -17,7 +17,7 @@ use Twig\Node\Node;
/**
* @author Julien Galenski <julien.galenski@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class DumpNode extends Node
{
@ -37,7 +37,7 @@ class DumpNode extends Node
/**
* {@inheritdoc}
*/
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
$compiler
->write("if (\$this->env->isDebug()) {\n")

View File

@ -18,7 +18,7 @@ use Twig\Node\Node;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class FormThemeNode extends Node
{
@ -27,7 +27,7 @@ class FormThemeNode extends Node
parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno, $tag);
}
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
$compiler
->addDebugInfo($this)

View File

@ -22,11 +22,11 @@ use Twig\Node\Expression\FunctionExpression;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class RenderBlockNode extends FunctionExpression
{
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
$compiler->addDebugInfo($this);
$arguments = iterator_to_array($this->getNode('arguments'));

View File

@ -19,11 +19,11 @@ use Twig\Node\Expression\FunctionExpression;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class SearchAndRenderBlockNode extends FunctionExpression
{
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
$compiler->addDebugInfo($this);
$compiler->raw('$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(');

View File

@ -20,7 +20,7 @@ use Twig\Node\Node;
*
* @author Wouter J <wouter@wouterj.nl>
*
* @final since Symfony 4.4
* @final
*/
class StopwatchNode extends Node
{
@ -29,7 +29,7 @@ class StopwatchNode extends Node
parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag);
}
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
$compiler
->addDebugInfo($this)

View File

@ -18,7 +18,7 @@ use Twig\Node\Node;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TransDefaultDomainNode extends Node
{
@ -27,7 +27,7 @@ class TransDefaultDomainNode extends Node
parent::__construct(['expr' => $expr], [], $lineno, $tag);
}
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
// noop as this node is just a marker for TranslationDefaultDomainNodeVisitor
}

View File

@ -25,7 +25,7 @@ class_exists('Twig\Node\Expression\ArrayExpression');
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TransNode extends Node
{
@ -48,7 +48,7 @@ class TransNode extends Node
parent::__construct($nodes, [], $lineno, $tag);
}
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
$compiler->addDebugInfo($this);

View File

@ -28,7 +28,7 @@ use Twig\NodeVisitor\AbstractNodeVisitor;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
{
@ -41,10 +41,8 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
/**
* {@inheritdoc}
*
* @return Node
*/
protected function doEnterNode(Node $node, Environment $env)
protected function doEnterNode(Node $node, Environment $env): Node
{
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->enter();
@ -95,10 +93,8 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
/**
* {@inheritdoc}
*
* @return Node|null
*/
protected function doLeaveNode(Node $node, Environment $env)
protected function doLeaveNode(Node $node, Environment $env): ?Node
{
if ($node instanceof TransDefaultDomainNode) {
return null;
@ -114,7 +110,7 @@ class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
/**
* {@inheritdoc}
*/
public function getPriority()
public function getPriority(): int
{
return -10;
}

View File

@ -23,7 +23,7 @@ use Twig\NodeVisitor\AbstractNodeVisitor;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TranslationNodeVisitor extends AbstractNodeVisitor
{
@ -51,10 +51,8 @@ class TranslationNodeVisitor extends AbstractNodeVisitor
/**
* {@inheritdoc}
*
* @return Node
*/
protected function doEnterNode(Node $node, Environment $env)
protected function doEnterNode(Node $node, Environment $env): Node
{
if (!$this->enabled) {
return $node;
@ -93,10 +91,8 @@ class TranslationNodeVisitor extends AbstractNodeVisitor
/**
* {@inheritdoc}
*
* @return Node|null
*/
protected function doLeaveNode(Node $node, Environment $env)
protected function doLeaveNode(Node $node, Environment $env): ?Node
{
return $node;
}
@ -104,7 +100,7 @@ class TranslationNodeVisitor extends AbstractNodeVisitor
/**
* {@inheritdoc}
*/
public function getPriority()
public function getPriority(): int
{
return 0;
}

View File

@ -27,16 +27,14 @@ use Twig\TokenParser\AbstractTokenParser;
*
* @author Julien Galenski <julien.galenski@gmail.com>
*
* @final since Symfony 4.4
* @final
*/
class DumpTokenParser extends AbstractTokenParser
{
/**
* {@inheritdoc}
*
* @return Node
*/
public function parse(Token $token)
public function parse(Token $token): Node
{
$values = null;
if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) {
@ -49,10 +47,8 @@ class DumpTokenParser extends AbstractTokenParser
/**
* {@inheritdoc}
*
* @return string
*/
public function getTag()
public function getTag(): string
{
return 'dump';
}

View File

@ -22,16 +22,14 @@ use Twig\TokenParser\AbstractTokenParser;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class FormThemeTokenParser extends AbstractTokenParser
{
/**
* Parses a token and returns a node.
*
* @return Node
* {@inheritdoc}
*/
public function parse(Token $token)
public function parse(Token $token): Node
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
@ -59,11 +57,9 @@ class FormThemeTokenParser extends AbstractTokenParser
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
* {@inheritdoc}
*/
public function getTag()
public function getTag(): string
{
return 'form_theme';
}

View File

@ -22,7 +22,7 @@ use Twig\TokenParser\AbstractTokenParser;
*
* @author Wouter J <wouter@wouterj.nl>
*
* @final since Symfony 4.4
* @final
*/
class StopwatchTokenParser extends AbstractTokenParser
{
@ -33,10 +33,7 @@ class StopwatchTokenParser extends AbstractTokenParser
$this->stopwatchIsAvailable = $stopwatchIsAvailable;
}
/**
* @return Node
*/
public function parse(Token $token)
public function parse(Token $token): Node
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
@ -62,10 +59,7 @@ class StopwatchTokenParser extends AbstractTokenParser
return $token->test('endstopwatch');
}
/**
* @return string
*/
public function getTag()
public function getTag(): string
{
return 'stopwatch';
}

View File

@ -21,16 +21,14 @@ use Twig\TokenParser\AbstractTokenParser;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TransDefaultDomainTokenParser extends AbstractTokenParser
{
/**
* {@inheritdoc}
*
* @return Node
*/
public function parse(Token $token)
public function parse(Token $token): Node
{
$expr = $this->parser->getExpressionParser()->parseExpression();
@ -41,10 +39,8 @@ class TransDefaultDomainTokenParser extends AbstractTokenParser
/**
* {@inheritdoc}
*
* @return string
*/
public function getTag()
public function getTag(): string
{
return 'trans_default_domain';
}

View File

@ -25,16 +25,14 @@ use Twig\TokenParser\AbstractTokenParser;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
* @final
*/
class TransTokenParser extends AbstractTokenParser
{
/**
* {@inheritdoc}
*
* @return Node
*/
public function parse(Token $token)
public function parse(Token $token): Node
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
@ -91,10 +89,8 @@ class TransTokenParser extends AbstractTokenParser
/**
* {@inheritdoc}
*
* @return string
*/
public function getTag()
public function getTag(): string
{
return 'trans';
}

View File

@ -18,7 +18,7 @@
"require": {
"php": "^7.2.9",
"symfony/translation-contracts": "^1.1",
"twig/twig": "^2.10"
"twig/twig": "^2.10|^3"
},
"require-dev": {
"egulias/email-validator": "^2.0",

View File

@ -59,7 +59,7 @@
"symfony/web-link": "^4.4|^5.0",
"doctrine/annotations": "~1.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0",
"twig/twig": "^2.4"
"twig/twig": "^2.4|^3"
},
"conflict": {
"phpdocumentor/reflection-docblock": "<3.0",

View File

@ -44,7 +44,7 @@
"symfony/yaml": "^4.4|^5.0",
"symfony/expression-language": "^4.4|^5.0",
"doctrine/doctrine-bundle": "^1.5|^2.0",
"twig/twig": "^2.4"
"twig/twig": "^2.4|^3"
},
"conflict": {
"symfony/browser-kit": "<4.4",

View File

@ -23,7 +23,7 @@
"symfony/http-foundation": "^4.4|^5.0",
"symfony/http-kernel": "^5.0",
"symfony/polyfill-ctype": "~1.8",
"twig/twig": "^2.10"
"twig/twig": "^2.10|^3"
},
"require-dev": {
"symfony/asset": "^4.4|^5.0",

View File

@ -23,7 +23,7 @@
"symfony/routing": "^4.4|^5.0",
"symfony/twig-bundle": "^4.4|^5.0",
"symfony/var-dumper": "^4.4|^5.0",
"twig/twig": "^2.10"
"twig/twig": "^2.10|^3"
},
"require-dev": {
"symfony/console": "^4.4|^5.0",

View File

@ -41,7 +41,7 @@
"symfony/translation-contracts": "^1.1",
"symfony/var-dumper": "^4.4|^5.0",
"psr/cache": "~1.0",
"twig/twig": "^2.4"
"twig/twig": "^2.4|^3"
},
"provide": {
"psr/log-implementation": "1.0"

View File

@ -23,7 +23,7 @@
"ext-iconv": "*",
"symfony/console": "^4.4|^5.0",
"symfony/process": "^4.4|^5.0",
"twig/twig": "^2.4"
"twig/twig": "^2.4|^3"
},
"conflict": {
"phpunit/phpunit": "<5.4.3",