8000 Support for Twig 3. · symfony/symfony@b050ccc · GitHub
[go: up one dir, main page]

Skip to content

Commit b050ccc

Browse files
committed
Support for Twig 3.
1 parent 117acc3 commit b050ccc

37 files changed

+53
-83
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"ext-xml": "*",
2121
"doctrine/event-manager": "~1.0",
2222
"doctrine/persistence": "~1.0",
23-
"twig/twig": "^2.10",
23+
"twig/twig": "^2.10|^3",
2424
"psr/cache": "~1.0",
2525
"psr/container": "^1.0",
2626
"psr/link": "^1.0",

src/Symfony/Bridge/Twig/Extension/AssetExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(Packages $packages)
3636
*
3737
* @return TwigFunction[]
3838
*/
39-
public function getFunctions()
39+
public function getFunctions(): array
4040
{
4141
return [
4242
new TwigFunction('asset', [$this, 'getAssetUrl']),

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct($fileLinkFormat, string $projectDir, string $charset
4545
*
4646
* @return TwigFilter[]
4747
*/
48-
public function getFilters()
48+
public function getFilters(): array
4949
{
5050
return [
5151
new TwigFilter('abbr_class', [$this, 'abbrClass'], ['is_safe' => ['html']]),

src/Symfony/Bridge/Twig/Extension/DumpExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(ClonerInterface $cloner, HtmlDumper $dumper = null)
4141
/**
4242
* @return TwigFunction[]
4343
*/
44-
public function getFunctions()
44+
public function getFunctions(): array
4545
{
4646
return [
4747
new TwigFunction('dump', [$this, 'dump'], ['is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true]),
@@ -51,7 +51,7 @@ public function getFunctions()
5151
/**
5252
* @return TokenParserInterface[]
5353
*/
54-
public function getTokenParsers()
54+
public function getTokenParsers(): array
5555
{
5656
return [new DumpTokenParser()];
5757
}

src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ExpressionExtension extends AbstractExtension
2929
*
3030
* @return TwigFunction[]
3131
*/
32-
public function getFunctions()
32+
public function getFunctions(): array
3333
{
3434
return [
3535
new TwigFunction('expression', [$this, 'createExpression']),

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FormExtension extends AbstractExtension
3535
*
3636
* @return TokenParserInterface[]
3737
*/
38-
public function getTokenParsers()
38+
public function getTokenParsers(): array
3939
{
4040
return [
4141
// {% form_theme form "SomeBundle::widgets.twig" %}
@@ -48,7 +48,7 @@ public function getTokenParsers()
4848
*
4949
* @return TwigFunction[]
5050
*/
51-
public function getFunctions()
51+
public function getFunctions(): array
5252
{
5353
return [
5454
new TwigFunction('form_widget', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
@@ -70,7 +70,7 @@ public function getFunctions()
7070
*
7171
* @return TwigFilter[]
7272
*/
73-
public function getFilters()
73+
public function getFilters(): array
7474
{
7575
return [
7676
new TwigFilter('humanize', ['Symfony\Component\Form\FormRenderer', 'humanize']),
@@ -83,7 +83,7 @@ public function getFilters()
8383
*
8484
* @return TwigTest[]
8585
*/
86-
public function getTests()
86+
public function getTests(): array
8787
{
8888
return [
8989
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),

src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(UrlHelper $urlHelper)
3737
*
3838
* @return TwigFunction[]
3939
*/
40-
public function getFunctions()
40+
public function getFunctions(): array
4141
{
4242
return [
4343
new TwigFunction('absolute_url', [$this, 'generateAbsoluteUrl']),

src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class HttpKernelExtension extends AbstractExtension
2727
/**
2828
* @return TwigFunction[]
2929
*/
30-
public function getFunctions()
30+
public function getFunctions(): array
3131
{
3232
return [
3333
new TwigFunction('render', [HttpKernelRuntime::class, 'renderFragment'], ['is_safe' => ['html']]),

src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(LogoutUrlGenerator $generator)
3636
*
3737
* @return TwigFunction[]
3838
*/
39-
public function getFunctions()
39+
public function getFunctions(): array
4040
{
4141
return [
4242
new TwigFunction('logout_url', [$this, 'getLogoutUrl']),

src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(Profile $profile, Stopwatch $stopwatch = null)
3333
$this->events = new \SplObjectStorage();
3434
}
3535

36-
public function enter(Profile $profile)
36+
public function enter(Profile $profile): void
3737
{
3838
if ($this->stopwatch && $profile->isTemplate()) {
3939
$this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
@@ -42,7 +42,7 @@ public function enter(Profile $profile)
4242
parent::enter($profile);
4343
}
4444

45-
public function leave(Profile $profile)
45+
public function leave(Profile $profile): void
4646
{
4747
parent::leave($profile);
4848

src/Symfony/Bridge/Twig/Extension/RoutingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(UrlGeneratorInterface $generator)
3939
*
4040
* @return TwigFunction[]
4141
*/
42-
public function getFunctions()
42+
public function getFunctions(): array
4343
{
4444
return [
4545
new TwigFunction('url', [$this, 'getUrl'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),

src/Symfony/Bridge/Twig/Extension/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function isGranted($role, object $object = null, string $field = null)
5555
*
5656
* @return TwigFunction[]
5757
*/
58-
public function getFunctions()
58+
public function getFunctions(): array
5959
{
6060
return [
6161
new TwigFunction('is_granted', [$this, 'isGranted']),

src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getStopwatch()
4242
/**
4343
* @return TokenParserInterface[]
4444
*/
45-
public function getTokenParsers()
45+
public function getTokenParsers(): array
4646
{
4747
return [
4848
/*

src/Symfony/Bridge/Twig/Extension/WebLinkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(RequestStack $requestStack)
3838
*
3939
* @return TwigFunction[]
4040
*/
41-
public function getFunctions()
41+
public function getFunctions(): array
4242
{
4343
return [
4444
new TwigFunction('link', [$this, 'link']),

src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(Registry $workflowRegistry)
3636
/**
3737
* @return TwigFunction[]
3838
*/
39-
public function getFunctions()
39+
public function getFunctions(): array
4040
{
4141
return [
4242
new TwigFunction('workflow_can', [$this, 'canTransition']),

src/Symfony/Bridge/Twig/Extension/YamlExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class YamlExtension extends AbstractExtension
3030
*
3131
* @return TwigFilter[]
3232
*/
33-
public function getFilters()
33+
public function getFilters(): array
3434
{
3535
return [
3636
new TwigFilter('yaml_encode', [$this, 'encode']),

src/Symfony/Bridge/Twig/Node/DumpNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct($varPrefix, Node $values = null, int $lineno, string
3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function compile(Compiler $compiler)
40+
public function compile(Compiler $compiler): void
4141
{
4242
$compiler
4343
->write("if (\$this->env->isDebug()) {\n")

src/Symfony/Bridge/Twig/Node/FormThemeNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(Node $form, Node $resources, int $lineno, string $ta
2727
parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno, $tag);
2828
}
2929

30-
public function compile(Compiler $compiler)
30+
public function compile(Compiler $compiler): void
3131
{
3232
$compiler
3333
->addDebugInfo($this)

src/Symfony/Bridge/Twig/Node/RenderBlockNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class RenderBlockNode extends FunctionExpression
2828
{
29-
public function compile(Compiler $compiler)
29+
public function compile(Compiler $compiler): void
3030
{
3131
$compiler->addDebugInfo($this);
3232
$arguments = iterator_to_array($this->getNode('arguments'));

src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
class SearchAndRenderBlockNode extends FunctionExpression
2525
{
26-
public function compile(Compiler $compiler)
26+
public function compile(Compiler $compiler): void
2727
{
2828
$compiler->addDebugInfo($this);
2929
$compiler->raw('$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(');

src/Symfony/Bridge/Twig/Node/StopwatchNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(Node $name, Node $body, AssignNameExpression $var, i
2929
parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag);
3030
}
3131

32-
public function compile(Compiler $compiler)
32+
public function compile(Compiler $compiler): void
3333
{
3434
$compiler
3535
->addDebugInfo($this)

src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(AbstractExpression $expr, int $lineno = 0, string $t
2727
parent::__construct(['expr' => $expr], [], $lineno, $tag);
2828
}
2929

30-
public function compile(Compiler $compiler)
30+
public function compile(Compiler $compiler): void
3131
{
3232
// noop as this node is just a marker for TranslationDefaultDomainNodeVisitor
3333
}

src/Symfony/Bridge/Twig/Node/TransNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Node $body, Node $domain = null, AbstractExpression
4848
parent::__construct($nodes, [], $lineno, $tag);
4949
}
5050

51-
public function compile(Compiler $compiler)
51+
public function compile(Compiler $compiler): void
5252
{
5353
$compiler->addDebugInfo($this);
5454

src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ public function __construct()
4141

4242
/**
4343
* {@inheritdoc}
44-
*
45-
* @return Node
4644
*/
47-
protected function doEnterNode(Node $node, Environment $env)
45+
protected function doEnterNode(Node $node, Environment $env): Node
4846
{
4947
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
5048
$this->scope = $this->scope->enter();
@@ -95,10 +93,8 @@ protected function doEnterNode(Node $node, Environment $env)
9593

9694
/**
9795
* {@inheritdoc}
98-
*
99-
* @return Node|null
10096
*/
101-
protected function doLeaveNode(Node $node, Environment $env)
97+
protected function doLeaveNode(Node $node, Environment $env): ?Node
10298
{
10399
if ($nod 10000 e instanceof TransDefaultDomainNode) {
104100
return null;
@@ -114,7 +110,7 @@ protected function doLeaveNode(Node $node, Environment $env)
114110
/**
115111
* {@inheritdoc}
116112
*/
117-
public function getPriority()
113+
public function getPriority(): int
118114
{
119115
return -10;
120116
}

src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ public function getMessages()
5151

5252
/**
5353
* {@inheritdoc}
54-
*
55-
* @return Node
5654
*/
57-
protected function doEnterNode(Node $node, Environment $env)
55+
protected function doEnterNode(Node $node, Environment $env): Node
5856
{
5957
if (!$this->enabled) {
6058
return $node;
@@ -93,18 +91,16 @@ protected function doEnterNode(Node $node, Environment $env)
9391

9492
/**
9593
* {@inheritdoc}
96-
*
97-
* @return Node|null
9894
*/
99-
protected function doLeaveNode(Node $node, Environment $env)
95+
protected function doLeaveNode(Node $node, Environment $env): ?Node
10096
{
10197
return $node;
10298
}
10399

104100
/**
105101
* {@inheritdoc}
106102
*/
107-
public function getPriority()
103+
public function getPriority(): int
108104
{
109105
return 0;
110106
}

src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ class DumpTokenParser extends AbstractTokenParser
3333
{
3434
/**
3535
* {@inheritdoc}
36-
*
37-
* @return Node
3836
*/
39-
public function parse(Token $token)
37+
public function parse(Token $token): Node
4038
{
4139
$values = null;
4240
if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) {
@@ -49,10 +47,8 @@ public function parse(Token $token)
4947

5048
/**
5149
* {@inheritdoc}
52-
*
53-
* @return string
5450
*/
55-
public function getTag()
51+
public function getTag(): string
5652
{
5753
return 'dump';
5854
}

src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
class FormThemeTokenParser extends AbstractTokenParser
2828
{
2929
/**
30-
* Parses a token and returns a node.
31-
*
32-
* @return Node
30+
* {@inheritdoc}
3331
*/
34-
public function parse(Token $token)
32+
public function parse(Token $token): Node
3533
{
3634
$lineno = $token->getLine();
3735
$stream = $this->parser->getStream();
@@ -59,11 +57,9 @@ public function parse(Token $token)
5957
}
6058

6159
/**
62-
* Gets the tag name associated with this token parser.
63-
*
64-
* @return string The tag name
60+
* {@inheritdoc}
6561
*/
66-
public function getTag()
62+
public function getTag(): string
6763
{
6864
return 'form_theme';
6965
}

src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public function __construct(bool $stopwatchIsAvailable)
3333
$this->stopwatchIsAvailable = $stopwatchIsAvailable;
3434
}
3535

36-
/**
37-
* @return Node
38-
*/
39-
public function parse(Token $token)
36+
public function parse(Token $token): Node
4037
{
4138
$lineno = $token->getLine();
4239
$stream = $this->parser->getStream();
@@ -62,10 +59,7 @@ public function decideStopwatchEnd(Token $token)
6259
return $token->test('endstopwatch');
6360
}
6461

65-
/**
66-
* @return string
67-
*/
68-
public function getTag()
62+
public function getTag(): string
6963
{
7064
return 'stopwatch';
7165
}

0 commit comments

Comments
 (0)
0