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

Skip to content

Commit b3b7570

Browse files
committed
Support for Twig 3.
1 parent b866172 commit b3b7570

40 files changed

+57
-79
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
@@ -34,7 +34,7 @@ public function __construct(Packages $packages)
3434
*
3535
* @return TwigFunction[]
3636
*/
37-
public function getFunctions()
37+
public function getFunctions(): array
3838
{
3939
return [
4040
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
@@ -43,7 +43,7 @@ public function __construct($fileLinkFormat, string $projectDir, string $charset
4343
*
4444
* @return TwigFilter[]
4545
*/
46-
public function getFilters()
46+
public function getFilters(): array
4747
{
4848
return [
4949
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
@@ -39,7 +39,7 @@ public function __construct(ClonerInterface $cloner, HtmlDumper $dumper = null)
3939
/**
4040
* @return TwigFunction[]
4141
*/
42-
public function getFunctions()
42+
public function getFunctions(): array
4343
{
4444
return [
4545
new TwigFunction('dump', [$this, 'dump'], ['is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true]),
@@ -49,7 +49,7 @@ public function getFunctions()
4949
/**
5050
* @return TokenParserInterface[]
5151
*/
52-
public function getTokenParsers()
52+
public function getTokenParsers(): array
5353
{
5454
return [new DumpTokenParser()];
5555
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ExpressionExtension extends AbstractExtension
2727
*
2828
* @return TwigFunction[]
2929
*/
30-
public function getFunctions()
30+
public function getFunctions(): array
3131
{
3232
return [
3333
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
@@ -33,7 +33,7 @@ class FormExtension extends AbstractExtension
3333
*
3434
* @return TokenParserInterface[]
3535
*/
36-
public function getTokenParsers()
36+
public function getTokenParsers(): array
3737
{
3838
return [
3939
// {% form_theme form "SomeBundle::widgets.twig" %}
@@ -46,7 +46,7 @@ public function getTokenParsers()
4646
*
4747
* @return TwigFunction[]
4848
*/
49-
public function getFunctions()
49+
public function getFunctions(): array
5050
{
5151
return [
5252
new TwigFunction('form_widget', null, ['node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => ['html']]),
@@ -68,7 +68,7 @@ public function getFunctions()
6868
*
6969
* @return TwigFilter[]
7070
*/
71-
public function getFilters()
71+
public function getFilters(): array
7272
{
7373
return [
7474
new TwigFilter('humanize', ['Symfony\Component\Form\FormRenderer', 'humanize']),
@@ -81,7 +81,7 @@ public function getFilters()
8181
*
8282
* @return TwigTest[]
8383
*/
84-
public function getTests()
84+
public function getTests(): array
8585
{
8686
return [
8787
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
@@ -35,7 +35,7 @@ public function __construct(UrlHelper $urlHelper)
3535
*
3636
* @return TwigFunction[]
3737
*/
38-
public function getFunctions()
38+
public function getFunctions(): array
3939
{
4040
return [
4141
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
@@ -25,7 +25,7 @@ class HttpKernelExtension extends AbstractExtension
2525
/**
2626
* @return TwigFunction[]
2727
*/
28-
public function getFunctions()
28+
public function getFunctions(): array
2929
{
3030
return [
3131
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
@@ -34,7 +34,7 @@ public function __construct(LogoutUrlGenerator $generator)
3434
*
3535
* @return TwigFunction[]
3636
*/
37-
public function getFunctions()
37+
public function getFunctions(): array
3838
{
3939
return [
4040
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
@@ -31,7 +31,7 @@ public function __construct(Profile $profile, Stopwatch $stopwatch = null)
3131
$this->events = new \SplObjectStorage();
3232
}
3333

34-
public function enter(Profile $profile)
34+
public function enter(Profile $profile): void
3535
{
3636
if ($this->stopwatch && $profile->isTemplate()) {
3737
$this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
@@ -40,7 +40,7 @@ public function enter(Profile $profile)
4040
parent::enter($profile);
4141
}
4242

43-
public function leave(Profile $profile)
43+
public function leave(Profile $profile): void
4444
{
4545
parent::leave($profile);
4646

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(UrlGeneratorInterface $generator)
3737
*
3838
* @return TwigFunction[]
3939
*/
40-
public function getFunctions()
40+
public function getFunctions(): array
4141
{
4242
return [
4343
new TwigFunction('url', [$this, 'getUrl'], ['is_safe_callba 10000 ck' => [$this, 'isUrlGenerationSafe']]),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function isGranted($role, object $object = null, string $field = null)
5353
*
5454
* @return TwigFunction[]
5555
*/
56-
public function getFunctions()
56+
public function getFunctions(): array
5757
{
5858
return [
5959
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
@@ -40,7 +40,7 @@ public function getStopwatch()
4040
/**
4141
* @return TokenParserInterface[]
4242
*/
43-
public function getTokenParsers()
43+
public function getTokenParsers(): array
4444
{
4545
return [
4646
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(RequestStack $requestStack)
3636
*
3737
* @return TwigFunction[]
3838
*/
39-
public function getFunctions()
39+
public function getFunctions(): array
4040
{
4141
return [
4242
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
@@ -34,7 +34,7 @@ public function __construct(Registry $workflowRegistry)
3434
/**
3535
* @return TwigFunction[]
3636
*/
37-
public function getFunctions()
37+
public function getFunctions(): array
3838
{
3939
return [
4040
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
@@ -28,7 +28,7 @@ class YamlExtension extends AbstractExtension
2828
*
2929
* @return TwigFilter[]
3030
*/
31-
public function getFilters()
31+
public function getFilters(): array
3232
{
3333
return [
3434
new TwigFilter('yaml_encode', [$this, 'encode']),

src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected function loadResourcesFromTheme(string $cacheKey, &$theme)
149149
{
150150
if (!$theme instanceof Template) {
151151
/* @var Template $theme */
152-
$theme = $this->environment->loadTemplate($theme);
152+
$theme = $this->environment->load($theme)->unwrap();
153153
}
154154

155155
if (null === $this->template) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($varPrefix, Node $values = null, int $lineno, string
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function compile(Compiler $compiler)
38+
public function compile(Compiler $compiler): void
3939
{
4040
$compiler
4141
->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
@@ -25,7 +25,7 @@ public function __construct(Node $form, Node $resources, int $lineno, string $ta
2525
parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno, $tag);
2626
}
2727

28-
public function compile(Compiler $compiler)
28+
public function compile(Compiler $compiler): void
2929
{
3030
$compiler
3131
->addDebugInfo($this)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class RenderBlockNode extends FunctionExpression
2626
{
27-
public function compile(Compiler $compiler)
27+
public function compile(Compiler $compiler): void
2828
{
2929
$compiler->addDebugInfo($this);
3030
$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
@@ -21,7 +21,7 @@
2121
*/
2222
class SearchAndRenderBlockNode extends FunctionExpression
2323
{
24-
public function compile(Compiler $compiler)
24+
public function compile(Compiler $compiler): void
2525
{
2626
$compiler->addDebugInfo($this);
2727
$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
@@ -27,7 +27,7 @@ public function __construct(Node $name, Node $body, AssignNameExpression $var, i
2727
parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $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/TransDefaultDomainNode.php

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

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

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

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

49-
public function compile(Compiler $compiler)
49+
public function compile(Compiler $compiler): void
5050
{
5151
$compiler->addDebugInfo($this);
5252

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

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

4040
/**
4141
* {@inheritdoc}
42-
*
43-
* @return Node
4442
*/
45-
protected function doEnterNode(Node $node, Environment $env)
43+
protected function doEnterNode(Node $node, Environment $env): Node
4644
{
4745
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
4846
$this->scope = $this->scope->enter();
@@ -93,10 +91,8 @@ 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
if ($node instanceof TransDefaultDomainNode) {
10298
return null;
@@ -112,7 +108,7 @@ protected function doLeaveNode(Node $node, Environment $env)
112108
/**
113109
* {@inheritdoc}
114110
*/
115-
public function getPriority()
111+
public function getPriority(): int
116112
{
117113
return -10;
118114
}

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

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

5050
/**
5151
* {@inheritdoc}
52-
*
53-
* @return Node
5452
*/
55-
protected function doEnterNode(Node $node, Environment $env)
53+
protected function doEnterNode(Node $node, Environment $env): Node
5654
{
5755
if (!$this->enabled) {
5856
return $node;
@@ -91,18 +89,16 @@ protected function doEnterNode(Node $node, Environment $env)
9189

9290
/**
9391
* {@inheritdoc}
94-
*
95-
* @return Node|null
9692
*/
97-
protected function doLeaveNode(Node $node, Environment $env)
93+
protected function doLeaveNode(Node $node, Environment $env): ?Node
9894
{
9995
return $node;
10096
}
10197

10298
/**
10399
* {@inheritdoc}
104100
*/
105-
public function getPriority()
101+
public function getPriority(): int
106102
{
107103
return 0;
108104
}

src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Symfony\Bridge\Twig\Extension\TranslationExtension;
1616
use Symfony\Component\Translation\Loader\ArrayLoader;
1717
use Symfony\Component\Translation\Translator;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1819
use Twig\Environment;
1920
use Twig\Loader\ArrayLoader as TwigArrayLoader;
21+
use Twig\TemplateWrapper;
2022

2123
class TranslationExtensionTest extends TestCase
2224
{
@@ -187,7 +189,7 @@ public function testDefaultTranslationDomainWithNamedArguments()
187189
$this->assertEquals('foo (custom)foo (foo)foo (custom)foo (custom)foo (fr)foo (custom)foo (fr)', trim($template->render([])));
188190
}
189191

190-
protected function getTemplate($template, $translator = null)
192+
private function getTemplate($template, TranslatorInterface $translator = null): TemplateWrapper
191193
{
192194
if (null === $translator) {
193195
$translator = new Translator('en');
@@ -201,6 +203,6 @@ protected function getTemplate($template, $translator = null)
201203
$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
202204
$twig->addExtension(new TranslationExtension($translator));
203205

204-
return $twig->loadTemplate('index');
206+
return $twig->load('index');
205207
}
206208
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ class DumpTokenParser extends AbstractTokenParser
3131
{
3232
/**
3333
* {@inheritdoc}
34-
*
35-
* @return Node
3634
*/
37-
public function parse(Token $token)
35+
public function parse(Token $token): Node
3836
{
3937
$values = null;
4038
if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) {
@@ -47,10 +45,8 @@ public function parse(Token $token)
4745

4846
/**
4947
* {@inheritdoc}
50-
*
51-
* @return string
5248
*/
53-
public function getTag()
49+
public function getTag(): string
5450
{
5551
return 'dump';
5652
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ class FormThemeTokenParser extends AbstractTokenParser
2626
{
2727
/**
2828
* Parses a token and returns a node.
29-
*
30-
* @return Node
3129
*/
32-
public function parse(Token $token)
30+
public function parse(Token $token): Node
3331
{
3432
$lineno = $token->getLine();
3533
$stream = $this->parser->getStream();
@@ -61,7 +59,7 @@ public function parse(Token $token)
6159
*
6260
* @return string The tag name
6361
*/
64-
public function getTag()
62+
public function getTag(): string
6563
{
6664
return 'form_theme';
6765
}

0 commit comments

Comments
 (0)
0