Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce53261

Browse files
nicolas-grekasfabpot
authored andcommitted
[DI] use filter_var() instead of XmlUtils::phpize() in EnvVarProcessor
1 parent 2bfcaeb commit ce53261

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\DependencyInjection;
1313

14-
use Symfony\Component\Config\Util\XmlUtils;
1514
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
1615
use Symfony\Component\DependencyInjection\Exception\LogicException;
1716
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@@ -112,19 +111,19 @@ public function getEnv($prefix, $name, \Closure $getEnv)
112111
}
113112

114113
if ('bool' === $prefix) {
115-
return (bool) self::phpize($env);
114+
return (bool) (filter_var($env, FILTER_VALIDATE_BOOLEAN) ?: filter_var($env, FILTER_VALIDATE_INT) ?: filter_var($env, FILTER_VALIDATE_FLOAT));
116115
}
117116

118117
if ('int' === $prefix) {
119-
if (!is_numeric($env = self::phpize($env))) {
118+
if (false === $env = filter_var($env, FILTER_VALIDATE_INT) ?: filter_var($env, FILTER_VALIDATE_FLOAT)) {
120119
throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to int.', $name));
121120
}
122121

123122
return (int) $env;
124123
}
125124

126125
if ('float' === $prefix) {
127-
if (!is_numeric($env = self::phpize($env))) {
126+
if (false === $env = filter_var($env, FILTER_VALIDATE_FLOAT)) {
128127
throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to float.', $name));
129128
}
130129

@@ -177,13 +176,4 @@ public function getEnv($prefix, $name, \Closure $getEnv)
177176

178177
throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
179178
}
180-
181-
private static function phpize($value)
182-
{
183-
if (!class_exists(XmlUtils::class)) {
184-
throw new LogicException('The Symfony Config component is required to cast env vars to "bool", "int" or "float".');
185-
}
186-
187-
return XmlUtils::phpize($value);
188-
}
189179
}

0 commit comments

Comments
 (0)