@@ -369,43 +369,42 @@ protected function load(string $file)
369
369
*/
370
370
protected function getEnv (string $ name )
371
371
{
372
- if (isset ($ this ->resolving [$ envName = "env( $ name) " ])) {
373
- throw new ParameterCircularReferenceException (array_keys ($ this ->resolving ));
374
- }
375
- if (isset ($ this ->envCache [$ name ]) || \array_key_exists ($ name , $ this ->envCache )) {
376
- return $ this ->envCache [$ name ];
377
- }
378
372
if (!$ this ->has ($ id = 'container.env_var_processors_locator ' )) {
379
373
$ this ->set ($ id , new ServiceLocator ([]));
380
374
}
381
- if (!$ this ->getEnv ) {
382
- $ this ->getEnv = \Closure::fromCallable ([$ this , 'getEnv ' ]);
383
- }
384
- $ processors = $ this ->get ($ id );
385
-
386
- if (false !== $ i = strpos ($ name , ': ' )) {
387
- $ prefix = substr ($ name , 0 , $ i );
388
- $ localName = substr ($ name , 1 + $ i );
389
- } else {
390
- $ prefix = 'string ' ;
391
- $ localName = $ name ;
392
- }
375
+ $ this ->getEnv ?? $ this ->getEnv = function ($ name , $ recursive = true ) use ($ id ) {
376
+ if (isset ($ this ->resolving [$ envName = "env( $ name) " ])) {
377
+ throw new ParameterCircularReferenceException (array_keys ($ this ->resolving ));
378
+ }
379
+ if (\array_key_exists ($ name , $ this ->envCache )) {
380
+ return $ this ->envCache [$ name ];
381
+ }
382
+
383
+ $ processors = $ this ->get ($ id );
384
+
385
+ if (false !== $ i = strpos ($ name , ': ' )) {
386
+ $ prefix = substr ($ name , 0 , $ i );
387
+ $ localName = substr ($ name , 1 + $ i );
388
+ } else {
389
+ $ prefix = 'string ' ;
390
+ $ localName = $ name ;
391
+ }
392
+
393
+ $ processor = $ processors ->has ($ prefix ) ? $ processors ->get ($ prefix ) : new EnvVarProcessor ($ this );
393
394
394
- if ($ processors ->has ($ prefix )) {
395
- $ processor = $ processors ->get ($ prefix );
396
- } else {
397
- $ processor = new EnvVarProcessor ($ this );
398
- if (false === $ i ) {
395
+ if (false === $ i && !$ recursive ) {
399
396
$ prefix = '' ;
400
397
}
401
- }
402
398
403
- $ this ->resolving [$ envName ] = true ;
404
- try {
405
- return $ this ->envCache [$ name ] = $ processor ->getEnv ($ prefix , $ localName , $ this ->getEnv );
406
- } finally {
407
- unset($ this ->resolving [$ envName ]);
408
- }
399
+ $ this ->resolving [$ envName ] = true ;
400
+ try {
401
+ return $ this ->envCache [$ name ] = $ processor ->getEnv ($ prefix , $ localName , $ this ->getEnv );
402
+ } finally {
403
+ unset($ this ->resolving [$ envName ]);
404
+ }
405
+ };
406
+
407
+ return ($ this ->getEnv )($ name , false );
409
408
}
410
409
411
410
/**
0 commit comments