From c0ab099aa5fdbc9eb722ff40433d383aa99c99d5 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Tue, 8 Jan 2019 19:51:17 +0100 Subject: [PATCH] Implement new function to receive env variable with prompt and default support but without the prefix --- Dotenv.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Dotenv.php b/Dotenv.php index 9ba622c..21a70c7 100644 --- a/Dotenv.php +++ b/Dotenv.php @@ -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()) { -- GitLab