Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 614f5da

Browse filesBrowse files
committed
[DI] remove support for non-string default env() parameters
1 parent bfa43d3 commit 614f5da
Copy full SHA for 614f5da

File tree

4 files changed

+15
-41
lines changed
Filter options

4 files changed

+15
-41
lines changed

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* removed support for auto-discovered extension configuration class which does not implement `ConfigurationInterface`
8+
* removed support for non-string default env() parameters
89

910
4.4.0
1011
-----

‎src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php
+4-23Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,8 @@ public function get($name)
4545
if (!preg_match('/^(?:\w*+:)*+\w++$/', $env)) {
4646
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
4747
}
48-
49-
if ($this->has($name)) {
50-
$defaultValue = parent::get($name);
51-
52-
if (null !== $defaultValue && !is_scalar($defaultValue)) { // !is_string in 5.0
53-
//throw new RuntimeException(sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', \gettype($defaultValue), $name));
54-
throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', \gettype($defaultValue), $name));
55-
} elseif (is_scalar($defaultValue) && !\is_string($defaultValue)) {
56-
@trigger_error(sprintf('A non-string default value of an env() parameter is deprecated since 4.3, cast "%s" to string instead.', $name), E_USER_DEPRECATED);
57-
}
48+
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {
49+
throw new RuntimeException(sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', \gettype($defaultValue), $name));
5850
}
5951

6052
$uniqueName = md5($name.uniqid(mt_rand(), true));
@@ -146,19 +138,8 @@ public function resolve()
146138
parent::resolve();
147139

148140
foreach ($this->envPlaceholders as $env => $placeholders) {
149-
if (!$this->has($name = "env($env)")) {
150-
continue;
151-
}
152-
if (is_numeric($default = $this->parameters[$name])) {
153-
if (!\is_string($default)) {
154-
@trigger_error(sprintf('A non-string default value of env parameter "%s" is deprecated since 4.3, cast it to string instead.', $env), E_USER_DEPRECATED);
155-
}
156-
$this->parameters[$name] = (string) $default;
157-
} elseif (null !== $default && !is_scalar($default)) { // !is_string in 5.0
158-
//throw new RuntimeException(sprintf('The default value of env parameter "%s" must be a string or null, %s given.', $env, \gettype($default)));
159-
throw new RuntimeException(sprintf('The default value of env parameter "%s" must be scalar or null, %s given.', $env, \gettype($default)));
160-
} elseif (is_scalar($default) && !\is_string($default)) {
161-
@trigger_error(sprintf('A non-string default value of env parameter "%s" is deprecated since 4.3, cast it to string instead.', $env), E_USER_DEPRECATED);
141+
if ($this->has($name = "env($env)") && null !== ($default = $this->parameters[$name]) && !\is_string($default)) {
142+
throw new RuntimeException(sprintf('The default value of env parameter "%s" must be a string or null, %s given.', $env, \gettype($default)));
162143
}
163144
}
164145
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function testDefaultEnvIsValidatedInConfig()
5959
}
6060

6161
/**
62-
* @group legacy
63-
* @expectedDeprecation A non-string default value of an env() parameter is deprecated since 4.3, cast "env(FLOATISH)" to string instead.
62+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
63+
* @expectedExceptionMessage The default value of an env() parameter must be a string or null, but "double" given to "env(FLOATISH)".
6464
*/
6565
public function testDefaultEnvWithoutPrefixIsValidatedInConfig()
6666
{
@@ -72,8 +72,6 @@ public function testDefaultEnvWithoutPrefixIsValidatedInConfig()
7272
]);
7373

7474
$this->doProcess($container);
75-
76-
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
7775
}
7876

7977
/**

‎src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php
+8-14Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,26 @@ public function testMergeWithDifferentIdentifiersForPlaceholders()
112112
}
113113

114114
/**
115-
* @group legacy
116-
* @expectedDeprecation A non-string default value of env parameter "INT_VAR" is deprecated since 4.3, cast it to string instead.
115+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
116+
* @expectedExceptionMessage The default value of env parameter "INT_VAR" must be a string or null, integer given.
117117
*/
118-
public function testResolveEnvCastsIntToString()
118+
public function testResolveEnvRequiresStrings()
119119
{
120120
$bag = new EnvPlaceholderParameterBag();
121121
$bag->get('env(INT_VAR)');
122122
$bag->set('env(INT_VAR)', 2);
123123
$bag->resolve();
124-
$this->assertSame('2', $bag->all()['env(INT_VAR)']);
125124
}
126125

127126
/**
128-
* @group legacy
129-
* @expectedDeprecation A non-string default value of an env() parameter is deprecated since 4.3, cast "env(INT_VAR)" to string instead.
130-
* @expectedDeprecation A non-string default value of env parameter "INT_VAR" is deprecated since 4.3, cast it to string instead.
127+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
128+
* @expectedExceptionMessage The default value of an env() parameter must be a string or null, but "integer" given to "env(INT_VAR)".
131129
*/
132130
public function testGetDefaultScalarEnv()
133131
{
134132
$bag = new EnvPlaceholderParameterBag();
135133
$bag->set('env(INT_VAR)', 2);
136-
$this->assertStringMatchesFormat('env_%s_INT_VAR_%s', $bag->get('env(INT_VAR)'));
137-
$this->assertSame(2, $bag->all()['env(INT_VAR)']);
138-
$bag->resolve();
139-
$this->assertStringMatchesFormat('env_%s_INT_VAR_%s', $bag->get('env(INT_VAR)'));
140-
$this->assertSame('2', $bag->all()['env(INT_VAR)']);
134+
$bag->get('env(INT_VAR)');
141135
}
142136

143137
public function testGetDefaultEnv()
@@ -163,7 +157,7 @@ public function testResolveEnvAllowsNull()
163157

164158
/**
165159
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
166-
* @expectedExceptionMessage The default value of env parameter "ARRAY_VAR" must be scalar or null, array given.
160+
* @expectedExceptionMessage The default value of env parameter "ARRAY_VAR" must be a string or null, array given.
167161
*/
168162
public function testResolveThrowsOnBadDefaultValue()
169163
{
@@ -185,7 +179,7 @@ public function testGetEnvAllowsNull()
185179

186180
/**
187181
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
188-
* @expectedExceptionMessage The default value of an env() parameter must be scalar or null, but "array" given to "env(ARRAY_VAR)".
182+
* @expectedExceptionMessage The default value of an env() parameter must be a string or null, but "array" given to "env(ARRAY_VAR)".
189183
*/
190184
public function testGetThrowsOnBadDefaultValue()
191185
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.