@@ -196,6 +196,10 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
196
196
throw new RuntimeException (sprintf ('Unsupported env var prefix "%s". ' , $ prefix ));
197
197
}
198
198
199
+ if (\in_array ($ prefix , ['string ' , 'bool ' , 'not ' , 'int ' , 'float ' ], true )) {
200
+ goto cast;
201
+ }
202
+
199
203
return null ;
200
204
}
201
205
@@ -209,6 +213,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
209
213
throw new RuntimeException (sprintf ('Non-scalar env var "%s" cannot be cast to "%s". ' , $ name , $ prefix ));
210
214
}
211
215
216
+ cast:
212
217
if ('string ' === $ prefix ) {
213
218
return (string ) $ env ;
214
219
}
@@ -220,15 +225,15 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
220
225
}
221
226
222
227
if ('int ' === $ prefix ) {
223
- if (false === $ env = filter_var ($ env , \FILTER_VALIDATE_INT ) ?: filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
228
+ if (null !== $ env && false === $ env = filter_var ($ env , \FILTER_VALIDATE_INT ) ?: filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
224
229
throw new RuntimeException (sprintf ('Non-numeric env var "%s" cannot be cast to int. ' , $ name ));
225
230
}
226
231
227
232
return (int ) $ env ;
228
233
}
229
234
230
235
if ('float ' === $ prefix ) {
231
- if (false === $ env = filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
236
+ if (null !== $ env && false === $ env = filter_var ($ env , \FILTER_VALIDATE_FLOAT )) {
232
237
throw new RuntimeException (sprintf ('Non-numeric env var "%s" cannot be cast to float. ' , $ name ));
233
238
}
234
239