Skip to content
Snippets Groups Projects
Commit c0ab099a authored by jurgenhaas's avatar jurgenhaas
Browse files

Implement new function to receive env variable with prompt and default support...

Implement new function to receive env variable with prompt and default support but without the prefix
parent c8ef74d3
No related branches found
Tags 1.0.0
No related merge requests found
......@@ -48,7 +48,7 @@ final class Dotenv {
}
/**
* Receive a value from the environment.
* Receive a value from the environment with the project name as prefix.
*
* First of all, it prefixes the key with the plugin name and converts the
* result into upper case. Then looking for the value with PHP's getenv and if
......@@ -67,7 +67,24 @@ final class Dotenv {
* The value.
*/
public function receive($key, $prompt, $default = '') {
$key = $this->name . '_' . strtoupper($key);
return $this->receiveGlobal($this->name . '_' . $key, $prompt, $default);
}
/**
* Receive a value from the environment.
*
* @param string $key
* The key of the environment variable.
* @param string $prompt
* The text being displayed when prompting the user.
* @param string $default
* The default value.
*
* @return string
* The value.
*/
public function receiveGlobal($key, $prompt, $default = '') {
$key = strtoupper($key);
$value = getenv($key);
if (empty($value)) {
if ($this->io->isInteractive()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment