@@ -26,7 +26,7 @@ class Loader
26
26
*
27
27
* @var bool
28
28
*/
29
- protected $ immutable = false ;
29
+ protected $ immutable ;
30
30
31
31
/**
32
32
* Create a new loader instance.
@@ -54,10 +54,7 @@ public function load()
54
54
$ filePath = $ this ->filePath ;
55
55
$ lines = $ this ->readLinesFromFile ($ filePath );
56
56
foreach ($ lines as $ line ) {
57
- if ($ this ->isComment ($ line )) {
58
- continue ;
59
- }
60
- if ($ this ->looksLikeSetter ($ line )) {
57
+ if (!$ this ->isComment ($ line ) && $ this ->looksLikeSetter ($ line )) {
61
58
$ this ->setEnvironmentVariable ($ line );
62
59
}
63
60
}
@@ -98,6 +95,7 @@ protected function normaliseEnvironmentVariable($name, $value)
98
95
list ($ name , $ value ) = $ this ->splitCompoundStringIntoParts ($ name , $ value );
99
96
list ($ name , $ value ) = $ this ->sanitiseVariableName ($ name , $ value );
100
97
list ($ name , $ value ) = $ this ->sanitiseVariableValue ($ name , $ value );
98
+
101
99
$ value = $ this ->resolveNestedVariables ($ value );
102
100
103
101
return array ($ name , $ value );
@@ -333,11 +331,12 @@ public function setEnvironmentVariable($name, $value = null)
333
331
334
332
// Don't overwrite existing environment variables if we're immutable
335
333
// Ruby's dotenv does this with `ENV[key] ||= value`.
336
- if ($ this ->immutable === true && $ this ->getEnvironmentVariable ($ name ) !== null ) {
334
+ if ($ this ->immutable && $ this ->getEnvironmentVariable ($ name ) !== null ) {
337
335
return ;
338
336
}
339
337
340
338
putenv ("$ name= $ value " );
339
+
341
340
$ _ENV [$ name ] = $ value ;
342
341
$ _SERVER [$ name ] = $ value ;
343
342
}
@@ -361,10 +360,12 @@ public function setEnvironmentVariable($name, $value = null)
361
360
public function clearEnvironmentVariable ($ name )
362
361
{
363
362
// Don't clear anything if we're immutable.
364
- if (!$ this ->immutable ) {
365
- putenv ($ name );
366
- unset($ _ENV [$ name ]);
367
- unset($ _SERVER [$ name ]);
363
+ if ($ this ->immutable ) {
364
+ return ;
368
365
}
366
+
367
+ putenv ($ name );
368
+
369
+ unset($ _ENV [$ name ], $ _SERVER [$ name ]);
369
370
}
370
371
}
0 commit comments