Skip to content

Commit 4e97b97

Browse files
committed
feature #25780 [TwigBundle] Deprecating "false" in favor of "kernel.debug" as default value of "strict_variable" (yceruto)
This PR was merged into the 4.1-dev branch. Discussion ---------- [TwigBundle] Deprecating "false" in favor of "kernel.debug" as default value of "strict_variable" | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - > http://symfony.com/doc/current/reference/configuration/twig.html#strict-variables >**strict_variables** > **type**: boolean **default**: `'%kernel.debug%'` Nope, really it's `false` by default: https://github.com/symfony/symfony/blob/1df45e43563a37633b50d4a36478090361a0b9de/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php#L130 Fixing it in symfony/symfony-docs#9050, but yes `'%kernel.debug%'` is a better default value, the [TwigBundle recipe](https://github.com/symfony/recipes/blob/bf2148f9f1fe5af7e19c3145b6f7246c6cabb3a5/symfony/twig-bundle/3.3/config/packages/twig.yaml#L4:) affirms that: ```yaml twig: # ... strict_variables: '%kernel.debug%' ``` So yeah, it definitely looks like it should be the default value, wdyt? Commits ------- 922878e Deprecating "false" as default value of "strict_variable" under Twig configuration
2 parents 32cc2e0 + 922878e commit 4e97b97

File tree

21 files changed

+80
-22
lines changed

21 files changed

+80
-22
lines changed

UPGRADE-4.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Translation
4747
* The `FileDumper::setBackup()` method is deprecated and will be removed in 5.0.
4848
* The `TranslationWriter::disableBackup()` method is deprecated and will be removed in 5.0.
4949

50+
TwigBundle
51+
----------
52+
53+
* Deprecated relying on the default value (`false`) of the `twig.strict_variables` configuration option. You should use `%kernel.debug%` explicitly instead, which will be the new default in 5.0.
54+
5055
Validator
5156
--------
5257

UPGRADE-5.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Translation
4040
* The `FileDumper::setBackup()` method has been removed.
4141
* The `TranslationWriter::disableBackup()` method has been removed.
4242

43+
TwigBundle
44+
----------
45+
46+
* The default value (`false`) of the `twig.strict_variables` configuration option has been changed to `%kernel.debug%`.
47+
4348
Validator
4449
--------
4550

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* added priority to Twig extensions
8+
* deprecated relying on the default value (`false`) of the `twig.strict_variables` configuration option. The `%kernel.debug%` parameter will be the new default in 5.0
89

910
4.0.0
1011
-----

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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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
));
Lines changed: 3 additions & 1 deletion
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+
));
Lines changed: 4 additions & 3 deletions
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
));

0 commit comments

Comments
 (0)