|
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\LogicException;
|
17 | 16 | use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
@@ -112,19 +111,19 @@ public function getEnv($prefix, $name, \Closure $getEnv)
|
112 | 111 | }
|
113 | 112 |
|
114 | 113 | 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)); |
116 | 115 | }
|
117 | 116 |
|
118 | 117 | 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)) { |
120 | 119 | throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to int.', $name));
|
121 | 120 | }
|
122 | 121 |
|
123 | 122 | return (int) $env;
|
124 | 123 | }
|
125 | 124 |
|
126 | 125 | if ('float' === $prefix) {
|
127 |
| - if (!is_numeric($env = self::phpize($env))) { |
| 126 | + if (false === $env = filter_var($env, FILTER_VALIDATE_FLOAT)) { |
128 | 127 | throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to float.', $name));
|
129 | 128 | }
|
130 | 129 |
|
@@ -177,13 +176,4 @@ public function getEnv($prefix, $name, \Closure $getEnv)
|
177 | 176 |
|
178 | 177 | throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
|
179 | 178 | }
|
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 |
| - } |
189 | 179 | }
|
0 commit comments