1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 08:30:07 +01:00

#473 Add feature to load server environment variables from special file

This commit is contained in:
Martin Peverelli
2018-09-24 16:03:04 -03:00
committed by Matt Stauffer
parent 2568be3255
commit 8971bf8d6a
2 changed files with 31 additions and 0 deletions

View File

@@ -177,4 +177,28 @@ protected function isActualFile($path)
{
return ! is_dir($path) && file_exists($path);
}
/**
* Load server environment variables if available.
*
* @param string $sitePath
* @param string $siteName
* @return void
*/
public function loadServerEnvironmentVariables($sitePath, $siteName)
{
$varFilePath = $sitePath . '/.valet-env.php';
if (! file_exists($varFilePath)) {
return;
}
$variables = include $varFilePath;
if (! isset($variables[$siteName])) {
return;
}
foreach ($variables[$siteName] as $key => $value) {
$_SERVER[$key] = $value;
}
}
}

View File

@@ -135,6 +135,13 @@ function valet_default_site_path($config)
return $valetDriver->serveStaticFile($staticFilePath, $valetSitePath, $siteName, $uri);
}
/**
* Attempt to load server environment variables.
*/
$valetDriver->loadServerEnvironmentVariables(
$valetSitePath, $siteName
);
/**
* Attempt to dispatch to a front controller.
*/