|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\DependencyInjection;
|
13 | 13 |
|
14 |
| -use Symfony\Component\Config\Util\XmlUtils; |
15 | 14 | use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
|
16 | 15 | use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
17 | 16 |
|
@@ -90,19 +89,19 @@ public function getEnv($prefix, $name, \Closure $getEnv)
|
90 | 89 | }
|
91 | 90 |
|
92 | 91 | 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)); |
94 | 93 | }
|
95 | 94 |
|
96 | 95 | 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)) { |
98 | 97 | throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to int.', $name));
|
99 | 98 | }
|
100 | 99 |
|
101 | 100 | return (int) $env;
|
102 | 101 | }
|
103 | 102 |
|
104 | 103 | if ('float' === $prefix) {
|
105 |
| - if (!is_numeric($env = self::phpize($env))) { |
| 104 | + if (false === $env = filter_var($env, FILTER_VALIDATE_FLOAT)) { |
106 | 105 | throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to float.', $name));
|
107 | 106 | }
|
108 | 107 |
|
@@ -151,13 +150,4 @@ public function getEnv($prefix, $name, \Closure $getEnv)
|
151 | 150 |
|
152 | 151 | throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
|
153 | 152 | }
|
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 |
| - } |
163 | 153 | }
|
0 commit comments