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

Skip to content

Commit fbf4e8e

Browse files
[DI] use filter_var() instead of XmlUtils::phpize() in EnvVarProcessor
1 parent 5d11205 commit fbf4e8e

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\RuntimeException;
1716

@@ -90,19 +89,19 @@ public function getEnv($prefix, $name, \Closure $getEnv)
9089
}
9190

9291
if ('bool' === $prefix) {
93-
return (bool) self::phpize($env);
92+
return (bool) (filter_var($env, FILTER_VALIDATE_BOOLEAN) ?: filter_var($env, FILTER_VALIDATE_INT) ?: filter_var($env, FILTER_VALIDATE_FLOAT));
9493
}
9594

9695
if ('int' === $prefix) {
97-
if (!is_numeric($env = self::phpize($env))) {
96+
if (false === $env = filter_var($env, FILTER_VALIDATE_INT) ?: filter_var($env, FILTER_VALIDATE_FLOAT)) {
9897
throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to int.', $name));
9998
}
10099

101100
return (int) $env;
102101
}
103102

104103
if ('float' === $prefix) {
105-
if (!is_numeric($env = self::phpize($env))) {
104+
if (false === $env = filter_var($env, FILTER_VALIDATE_FLOAT)) {
106105
throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to float.', $name));
107106
}
108107

@@ -151,13 +150,4 @@ public function getEnv($prefix, $name, \Closure $getEnv)
151150

152151
throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
153152
}
154-
155-
private static function phpize($value)
156-
{
157-
if (!class_exists(XmlUtils::class)) {
158-
throw new RuntimeException('The Symfony Config component is required to cast env vars to "bool", "int" or "float".');
159-
}
160-
161-
return XmlUtils::phpize($value);
162-
}
163153
}

0 commit comments

Comments
 (0)