|
|
|
|
@ -21,19 +21,39 @@ class DotEnv {
|
|
|
|
|
? [$parts[0], implode('=', array_slice($parts, 1))]
|
|
|
|
|
: $parts
|
|
|
|
|
);
|
|
|
|
|
$vars[$varname] = $value;
|
|
|
|
|
$trimmedValue = trim($value);
|
|
|
|
|
$vars[trim($varname)] = self::removeOuterQuotes($trimmedValue);
|
|
|
|
|
return $vars;
|
|
|
|
|
}, []);
|
|
|
|
|
return $envvars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function MUTATE_SERVER_addEnvVars(array $variables) {
|
|
|
|
|
$_SERVER = array_merge($_SERVER, $variables);
|
|
|
|
|
public static function removeOuterQuotes(string $string, $quote = "'"): string {
|
|
|
|
|
$lastCharIndex = strlen($string) - 1;
|
|
|
|
|
$stringWithoutOuterQuotes = strpos($string, $quote) === 0 && strpos($string, $quote, -1) === $lastCharIndex
|
|
|
|
|
? substr($string, 1, $lastCharIndex)
|
|
|
|
|
: $string;
|
|
|
|
|
|
|
|
|
|
if ($quote === '"') {
|
|
|
|
|
return $stringWithoutOuterQuotes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$noQuotesRemoved = strlen($stringWithoutOuterQuotes) === strlen($string);
|
|
|
|
|
|
|
|
|
|
if ($noQuotesRemoved && $quote === "'") {
|
|
|
|
|
return self::removeOuterQuotes($string, '"');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $stringWithoutOuterQuotes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function MUTATE_ENV_addEnvVars(array $variables) {
|
|
|
|
|
$_ENV = array_merge($_ENV, $variables);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function load(string $rootDir) {
|
|
|
|
|
$envvars = self::loadFromFile($rootDir . DIRECTORY_SEPARATOR . '.env');
|
|
|
|
|
self::MUTATE_SERVER_addEnvVars($envvars);
|
|
|
|
|
self::MUTATE_ENV_addEnvVars($envvars);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|