Skip to content

Commit 19f30e2

Browse files
committed
Deprecating "false" as default value of "strict_variable" under Twig configuration
1 parent 1df45e4 commit 19f30e2

18 files changed

+69
-22
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLogin/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
imports:
2-
- { resource: ./../config/framework.yml }
2+
- { resource: ./../config/default.yml }
33

44
security:
55
encoders:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLogin/custom_handlers.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
imports:
2-
- { resource: ./../config/framework.yml }
2+
- { resource: ./../config/default.yml }
33

44
security:
55
encoders:

src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
127127
->scalarNode('cache')->defaultValue('%kernel.cache_dir%/twig')->end()
128128
->scalarNode('charset')->defaultValue('%kernel.charset%')->end()
129129
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
130-
->booleanNode('strict_variables')->end()
130+
->booleanNode('strict_variables')
131+
->defaultValue(function () {
132+
@trigger_error('Relying on the default value ("false") of the "twig.strict_variables" configuration option is deprecated since Symfony 4.1. You should use "%kernel.debug%" explicitly instead, which will be the new default in 5.0.', E_USER_DEPRECATED);
133+
134+
return false;
135+
})
136+
->end()
131137
->scalarNode('auto_reload')->end()
132138
->integerNode('optimizations')->min(-1)->end()
133139
->scalarNode('default_path')

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ConfigurationTest extends TestCase
2020
public function testDoNoDuplicateDefaultFormResources()
2121
{
2222
$input = array(
23+
'strict_variables' => false, // to be removed in 5.0 relying on default
2324
'form_themes' => array('form_div_layout.html.twig'),
2425
);
2526

@@ -28,4 +29,16 @@ public function testDoNoDuplicateDefaultFormResources()
2829

2930
$this->assertEquals(array('form_div_layout.html.twig'), $config['form_themes']);
3031
}
32+
33+
/**
34+
* @group legacy
35+
* @expectedDeprecation Relying on the default value ("false") of the "twig.strict_variables" configuration option is deprecated since Symfony 4.1. You should use "%kernel.debug%" explicitly instead, which will be the new default in 5.0.
36+
*/
37+
public function testGetStrictVariablesDefaultFalse()
38+
{
39+
$processor = new Processor();
40+
$config = $processor->processConfiguration(new Configuration(), array(array()));
41+
42+
$this->assertFalse($config['strict_variables']);
43+
}
3144
}

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
$container->loadFromExtension('twig', array(
44
'autoescape_service' => 'my_project.some_bundle.template_escaping_guesser',
55
'autoescape_service_method' => 'guess',
6+
'strict_variables' => false, // to be removed in 5.0 relying on default
67
));
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<?php
22

3-
$container->loadFromExtension('twig', array());
3+
$container->loadFromExtension('twig', array(
4+
'strict_variables' => false, // to be removed in 5.0 relying on default
5+
));
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

33
$container->loadFromExtension('twig', array(
4-
'paths' => array(
5-
'namespaced_path3' => 'namespace3',
6-
),
4+
'paths' => array(
5+
'namespaced_path3' => 'namespace3',
6+
),
7+
'strict_variables' => false, // to be removed in 5.0 relying on default
78
));

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/formats.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
'decimal_point' => ',',
1212
'thousands_separator' => '.',
1313
),
14+
'strict_variables' => false, // to be removed in 5.0 relying on default
1415
));

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
77
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
88

9-
<twig:config autoescape-service="my_project.some_bundle.template_escaping_guesser" autoescape-service-method="guess" />
9+
<twig:config autoescape-service="my_project.some_bundle.template_escaping_guesser" autoescape-service-method="guess" strict-variables="false" />
1010
</container>

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/empty.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
77
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
88

9-
<twig:config />
9+
<twig:config strict-variables="false" />
1010
</container>

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/formats.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
66
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
77

8-
<twig:config>
8+
<twig:config strict-variables="false">
99
<twig:date format="Y-m-d" interval-format="%d" timezone="Europe/Berlin" />
1010
<twig:number-format decimals="2" decimal-point="," thousands-separator="." />
1111
</twig:config>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
twig:
22
autoescape_service: my_project.some_bundle.template_escaping_guesser
33
autoescape_service_method: guess
4+
strict_variables: false # to be removed in 5.0 relying on default
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
twig:
2+
strict_variables: false # to be removed in 5.0 relying on default
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
twig:
2+
strict_variables: false # to be removed in 5.0 relying on default
23
paths:
34
namespaced_path3: namespace3

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/formats.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
twig:
2+
strict_variables: false # to be removed in 5.0 relying on default
23
date:
34
format: Y-m-d
45
interval_format: '%d'

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function testLoadEmptyConfiguration()
2929
{
3030
$container = $this->createContainer();
3131
$container->registerExtension(new TwigExtension());
32-
$container->loadFromExtension('twig', array());
32+
$container->loadFromExtension('twig', array(
33+
'strict_variables' => false, // to be removed in 5.0 relying on default
34+
));
3335
$this->compileContainer($container);
3436

3537
$this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file');
@@ -151,7 +153,10 @@ public function testGlobalsWithDifferentTypesAndValues()
151153

152154
$container = $this->createContainer();
153155
$container->registerExtension(new TwigExtension());
154-
$container->loadFromExtension('twig', array('globals' => $globals));
156+
$container->loadFromExtension('twig', array(
157+
'globals' => $globals,
158+
'strict_variables' => false, // // to be removed in 5.0 relying on default
159+
));
155160
$this->compileContainer($container);
156161

157162
$calls = $container->getDefinition('twig')->getMethodCalls();
@@ -217,7 +222,9 @@ public function testStopwatchExtensionAvailability($debug, $stopwatchEnabled, $e
217222
$container->register('debug.stopwatch', 'Symfony\Component\Stopwatch\Stopwatch');
218223
}
219224
$container->registerExtension(new TwigExtension());
220-
$container->loadFromExtension('twig', array());
225+
$container->loadFromExtension('twig', array(
226+
'strict_variables' => false, // to be removed in 5.0 relying on default
227+
));
221228
$container->setAlias('test.twig.extension.debug.stopwatch', 'twig.extension.debug.stopwatch')->setPublic(true);
222229
$this->compileContainer($container);
223230

@@ -242,7 +249,9 @@ public function testRuntimeLoader()
242249
{
243250
$container = $this->createContainer();
244251
$container->registerExtension(new TwigExtension());
245-
$container->loadFromExtension('twig', array());
252+
$container->loadFromExtension('twig', array(
253+
'strict_variables' => false, // to be removed in 5.0 relying on default
254+
));
246255
$container->setParameter('kernel.environment', 'test');
247256
$container->setParameter('debug.file_link_format', 'test');
248257
$container->setParameter('foo', 'FooClass');

src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ public function registerBundles()
8989
public function registerContainerConfiguration(LoaderInterface $loader)
9090
{
9191
$loader->load(function ($container) {
92-
$container->loadFromExtension('framework', array(
93-
'secret' => '$ecret',
94-
'form' => array('enabled' => false),
95-
));
92+
$container
93+
->loadFromExtension('framework', array(
94+
'secret' => '$ecret',
95+
'form' => array('enabled' => false),
96+
))
97+
->loadFromExtension('twig', array( // to be removed in 5.0 relying on default
98+
'strict_variables' => false,
99+
))
100+
;
96101
});
97102

98103
if ($this->withTemplating) {

src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ public function registerBundles()
6161
public function registerContainerConfiguration(LoaderInterface $loader)
6262
{
6363
$loader->load(function ($container) {
64-
$container->loadFromExtension('framework', array(
65-
'secret' => '$ecret',
66-
'form' => array('enabled' => false),
67-
));
64+
$container
65+
->loadFromExtension('framework', array(
66+
'secret' => '$ecret',
67+
'form' => array('enabled' => false),
68+
))
69+
->loadFromExtension('twig', array( // to be removed in 5.0 relying on default
70+
'strict_variables' => false,
71+
))
72+
;
6873
});
6974
}
7075

0 commit comments

Comments
 (0)