Sven\FlexEnv\Env::get PHP Méthode

get() public méthode

Get an entry from the .env file by key.
public get ( string $key ) : string
$key string
Résultat string
    public function get($key)
    {
        $env = $this->parseFile();
        $result = $env->filter(function (Collection $value) use($key) {
            return $value->first() == $key;
        })->first();
        return $result instanceof Collection ? $result->get(1) : $result;
    }

Usage Example

Exemple #1
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function handle()
 {
     $env = new Env(base_path('.env'));
     $key = strtoupper($this->argument('key'));
     $result = str_replace('"', '', $env->get($key));
     if ($result == '' || is_null($result)) {
         return $this->error("Could not find a value for [{$key}] in your .env file.");
     }
     return $this->comment("The value for [{$key}] is \"{$result}\".");
 }