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:1df45e4356/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php (L130)
Fixing it in https://github.com/symfony/symfony-docs/pull/9050, but yes `'%kernel.debug%'` is a better default value, the [TwigBundle recipe](bf2148f9f1/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 -------922878ee53
Deprecating "false" as default value of "strict_variable" under Twig configuration
This commit is contained in:
commit
4e97b97215
@ -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
|
||||
--------
|
||||
|
||||
|
@ -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
|
||||
--------
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
imports:
|
||||
- { resource: ./../config/framework.yml }
|
||||
- { resource: ./../config/default.yml }
|
||||
|
||||
security:
|
||||
encoders:
|
||||
|
@ -1,5 +1,5 @@
|
||||
imports:
|
||||
- { resource: ./../config/framework.yml }
|
||||
- { resource: ./../config/default.yml }
|
||||
|
||||
security:
|
||||
encoders:
|
||||
|
@ -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
|
||||
-----
|
||||
|
@ -127,7 +127,13 @@ class Configuration implements ConfigurationInterface
|
||||
->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')
|
||||
|
@ -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'),
|
||||
);
|
||||
|
||||
@ -28,4 +29,16 @@ class ConfigurationTest extends TestCase
|
||||
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
));
|
||||
|
@ -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
|
||||
));
|
||||
|
@ -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
|
||||
));
|
||||
|
@ -11,4 +11,5 @@ $container->loadFromExtension('twig', array(
|
||||
'decimal_point' => ',',
|
||||
'thousands_separator' => '.',
|
||||
),
|
||||
'strict_variables' => false, // to be removed in 5.0 relying on default
|
||||
));
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
@ -1 +1,2 @@
|
||||
twig:
|
||||
strict_variables: false # to be removed in 5.0 relying on default
|
||||
|
@ -1,3 +1,4 @@
|
||||
twig:
|
||||
strict_variables: false # to be removed in 5.0 relying on default
|
||||
paths:
|
||||
namespaced_path3: namespace3
|
||||
|
@ -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'
|
||||
|
@ -29,7 +29,9 @@ class TwigExtensionTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
@ -151,7 +153,10 @@ class TwigExtensionTest extends TestCase
|
||||
|
||||
$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();
|
||||
@ -217,7 +222,9 @@ class TwigExtensionTest extends TestCase
|
||||
$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);
|
||||
|
||||
@ -242,7 +249,9 @@ class TwigExtensionTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
|
@ -89,10 +89,15 @@ class CacheWarmingKernel extends Kernel
|
||||
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) {
|
||||
|
@ -61,10 +61,15 @@ class NoTemplatingEntryKernel extends Kernel
|
||||
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,
|
||||
))
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user