mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
Updated loading of server environment variables
- added `putenv()` for Laravel compatibility
- added `$_ENV` for generic compatibility
- added wildcard processing, so site array named `*` gets processed always (if present), and then site-specific entries are added and will override the wildcard.
Sample `.valet-env.php`:
```php
<?php
return [
'*' => [
'USER' => 'vagrant',
],
'demo' => [
'MY_CUSTOM_VAR' => 'special_value',
'USER' => 'travis',
],
];
```
(Note: order of entries in the array is irrelevant, as the parser reads `*` first, followed by site-specific entries.)
This commit is contained in:
committed by
Matt Stauffer
parent
8971bf8d6a
commit
67546f1fc3
@@ -180,6 +180,7 @@ protected function isActualFile($path)
|
||||
|
||||
/**
|
||||
* Load server environment variables if available.
|
||||
* Processes any '*' entries first, and then adds site-specific entries
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
@@ -193,12 +194,19 @@ public function loadServerEnvironmentVariables($sitePath, $siteName)
|
||||
}
|
||||
|
||||
$variables = include $varFilePath;
|
||||
if (! isset($variables[$siteName])) {
|
||||
return;
|
||||
|
||||
$variablesToSet = isset($variables['*']) ? $variables['*'] : [];
|
||||
|
||||
if (isset($variables[$siteName])) {
|
||||
$variablesToSet = array_merge($variablesToSet, $variables[$siteName]);
|
||||
}
|
||||
|
||||
foreach ($variables[$siteName] as $key => $value) {
|
||||
foreach ($variablesToSet as $key => $value) {
|
||||
if (! is_string($key)) continue;
|
||||
$_SERVER[$key] = $value;
|
||||
$_ENV[$key] = $value;
|
||||
putenv($key . '=' . $value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user