Skip to content

Commit 97c3b3d

Browse files
Merge branch '4.1'
* 4.1: [DI] Remove default env type check on validate [FrameworkBundle][TwigBridge] Fix BC break from strong dependency on CSRF token storage
2 parents c001098 + ed37583 commit 97c3b3d

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

Compiler/ValidateEnvPlaceholdersPass.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Config\Definition\BaseNode;
1515
use Symfony\Component\Config\Definition\Processor;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17-
use Symfony\Component\DependencyInjection\Exception\LogicException;
1817
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
1918
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
2019
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -42,21 +41,20 @@ public function process(ContainerBuilder $container)
4241
return;
4342
}
4443

45-
$defaultBag = new ParameterBag($container->getParameterBag()->all());
44+
$defaultBag = new ParameterBag($resolvingBag->all());
4645
$envTypes = $resolvingBag->getProvidedTypes();
4746
try {
4847
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
49-
$prefix = (false === $i = strpos($env, ':')) ? 'string' : substr($env, 0, $i);
50-
$types = $envTypes[$prefix] ?? array('string');
51-
$default = ($hasEnv = (false === $i && $defaultBag->has("env($env)"))) ? $defaultBag->get("env($env)") : null;
52-
53-
if (null !== $default && !in_array($type = self::getType($default), $types, true)) {
54-
throw new LogicException(sprintf('Invalid type for env parameter "env(%s)". Expected "%s", but got "%s".', $env, implode('", "', $types), $type));
55-
}
56-
5748
$values = array();
58-
foreach ($types as $type) {
59-
$values[$type] = $hasEnv ? $default : self::$typeFixtures[$type] ?? null;
49+
if (false === $i = strpos($env, ':')) {
50+
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : null;
51+
$defaultType = null !== $default ? self::getType($default) : 'string';
52+
$values[$defaultType] = $default;
53+
} else {
54+
$prefix = substr($env, 0, $i);
55+
foreach ($envTypes[$prefix] ?? array('string') as $type) {
56+
$values[$type] = self::$typeFixtures[$type] ?? null;
57+
}
6058
}
6159
foreach ($placeholders as $placeholder) {
6260
BaseNode::setPlaceholder($placeholder, $values);

Tests/Compiler/ValidateEnvPlaceholdersPassTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@
2222

2323
class ValidateEnvPlaceholdersPassTest extends TestCase
2424
{
25-
/**
26-
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
27-
* @expectedExceptionMessage Invalid type for env parameter "env(FOO)". Expected "string", but got "bool".
28-
*/
29-
public function testDefaultEnvIsValidatedByType()
25+
public function testEnvsAreValidatedInConfig()
3026
{
3127
$container = new ContainerBuilder();
32-
$container->setParameter('env(FOO)', true);
33-
$container->registerExtension(new EnvExtension());
34-
$container->prependExtensionConfig('env_extension', array(
35-
'scalar_node' => '%env(FOO)%',
28+
$container->setParameter('env(NULLED)', null);
29+
$container->setParameter('env(FLOATISH)', 3.2);
30+
$container->registerExtension($ext = new EnvExtension());
31+
$container->prependExtensionConfig('env_extension', $expected = array(
32+
'scalar_node' => '%env(NULLED)%',
33+
'scalar_node_not_empty' => '%env(FLOATISH)%',
34+
'int_node' => '%env(int:FOO)%',
35+
'float_node' => '%env(float:BAR)%',
3636
));
3737

3838
$this->doProcess($container);
39+
40+
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
3941
}
4042

41-
public function testEnvsAreValidatedInConfig()
43+
public function testDefaultEnvWithoutPrefixIsValidatedInConfig()
4244
{
4345
$container = new ContainerBuilder();
44-
$container->setParameter('env(NULLED)', null);
46+
$container->setParameter('env(FLOATISH)', 3.2);
4547
$container->registerExtension($ext = new EnvExtension());
4648
$container->prependExtensionConfig('env_extension', $expected = array(
47-
'scalar_node' => '%env(NULLED)%',
48-
'int_node' => '%env(int:FOO)%',
49-
'float_node' => '%env(float:BAR)%',
49+
'float_node' => '%env(FLOATISH)%',
5050
));
5151

5252
$this->doProcess($container);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them"
3333
},
3434
"conflict": {
35-
"symfony/config": "<4.1",
35+
"symfony/config": "<4.1.1",
3636
"symfony/finder": "<3.4",
3737
"symfony/proxy-manager-bridge": "<3.4",
3838
"symfony/yaml": "<3.4"

0 commit comments

Comments
 (0)