Skip to content

[TwigBundle] Deprecating "false" in favor of "kernel.debug" as default value of "strict_variable" #25780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-4.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Translation
* The `FileDumper::setBackup()` method is deprecated and will be removed in 5.0.
* The `TranslationWriter::disableBackup()` method is deprecated and will be removed in 5.0.

TwigBundle
----------

* 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.

Validator
--------

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Translation
* The `FileDumper::setBackup()` method has been removed.
* The `TranslationWriter::disableBackup()` method has been removed.

TwigBundle
----------

* The default value (`false`) of the `twig.strict_variables` configuration option has been changed to `%kernel.debug%`.

Validator
--------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- { resource: ./../config/framework.yml }
- { resource: ./../config/default.yml }

security:
encoders:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- { resource: ./../config/framework.yml }
- { resource: ./../config/default.yml }

security:
encoders:
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/TwigBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-----

* added priority to Twig extensions
* 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

4.0.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
->scalarNode('cache')->defaultValue('%kernel.cache_dir%/twig')->end()
->scalarNode('charset')->defaultValue('%kernel.charset%')->end()
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
->booleanNode('strict_variables')->end()
->booleanNode('strict_variables')
->defaultValue(function () {
@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);

return false;
})
->end()
->scalarNode('auto_reload')->end()
->integerNode('optimizations')->min(-1)->end()
->scalarNode('default_path')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ConfigurationTest extends TestCase
public function testDoNoDuplicateDefaultFormResources()
{
$input = array(
'strict_variables' => false, // to be removed in 5.0 relying on default
'form_themes' => array('form_div_layout.html.twig'),
);

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

$this->assertEquals(array('form_div_layout.html.twig'), $config['form_themes']);
}

/**
* @group legacy
* @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.
*/
public function testGetStrictVariablesDefaultFalse()
{
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array(array()));

$this->assertFalse($config['strict_variables']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
$container->loadFromExtension('twig', array(
'autoescape_service' => 'my_project.some_bundle.template_escaping_guesser',
'autoescape_service_method' => 'guess',
'strict_variables' => false, // to be removed in 5.0 relying on default
));
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

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

$container->loadFromExtension('twig', array(
'paths' => array(
'namespaced_path3' => 'namespace3',
),
'paths' => array(
'namespaced_path3' => 'namespace3',
),
'strict_variables' => false, // to be removed in 5.0 relying on default
));
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
'decimal_point' => ',',
'thousands_separator' => '.',
),
'strict_variables' => false, // to be removed in 5.0 relying on default
));
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">

<twig:config autoescape-service="my_project.some_bundle.template_escaping_guesser" autoescape-service-method="guess" />
<twig:config autoescape-service="my_project.some_bundle.template_escaping_guesser" autoescape-service-method="guess" strict-variables="false" />
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">

<twig:config />
<twig:config strict-variables="false" />
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">

<twig:config>
<twig:config strict-variables="false">
<twig:date format="Y-m-d" interval-format="%d" timezone="Europe/Berlin" />
<twig:number-format decimals="2" decimal-point="," thousands-separator="." />
</twig:config>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
twig:
autoescape_service: my_project.some_bundle.template_escaping_guesser
autoescape_service_method: guess
strict_variables: false # to be removed in 5.0 relying on default
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
twig:
strict_variables: false # to be removed in 5.0 relying on default
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
twig:
strict_variables: false # to be removed in 5.0 relying on default
paths:
namespaced_path3: namespace3
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
twig:
strict_variables: false # to be removed in 5.0 relying on default
date:
format: Y-m-d
interval_format: '%d'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function testLoadEmptyConfiguration()
{
$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
$container->loadFromExtension('twig', array());
$container->loadFromExtension('twig', array(
'strict_variables' => false, // to be removed in 5.0 relying on default
));
$this->compileContainer($container);

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

$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
$container->loadFromExtension('twig', array('globals' => $globals));
$container->loadFromExtension('twig', array(
'globals' => $globals,
'strict_variables' => false, // // to be removed in 5.0 relying on default
));
$this->compileContainer($container);

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

Expand All @@ -242,7 +249,9 @@ public function testRuntimeLoader()
{
$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
$container->loadFromExtension('twig', array());
$container->loadFromExtension('twig', array(
'strict_variables' => false, // to be removed in 5.0 relying on default
));
$container->setParameter('kernel.environment', 'test');
$container->setParameter('debug.file_link_format', 'test');
$container->setParameter('foo', 'FooClass');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ public function registerBundles()
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function ($container) {
$container->loadFromExtension('framework', array(
'secret' => '$ecret',
'form' => array('enabled' => false),
));
$container
->loadFromExtension('framework', array(
'secret' => '$ecret',
'form' => array('enabled' => false),
))
->loadFromExtension('twig', array( // to be removed in 5.0 relying on default
'strict_variables' => false,
))
;
});

if ($this->withTemplating) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ public function registerBundles()
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function ($container) {
$container->loadFromExtension('framework', array(
'secret' => '$ecret',
'form' => array('enabled' => false),
));
$container
->loadFromExtension('framework', array(
'secret' => '$ecret',
'form' => array('enabled' => false),
))
->loadFromExtension('twig', array( // to be removed in 5.0 relying on default
'strict_variables' => false,
))
;
});
}

Expand Down