get() public method

Get the value from environment variables for the given $key.
public get ( string $key, null $value = null ) : string
$key string Key name.
$value null Default value that will be returned if the $key is not found.
return string Value under the defined $key.
コード例 #1
0
ファイル: EnvTest.php プロジェクト: Webiny/Framework
 public function testGet()
 {
     $_ENV = ["APP_ENV" => "development"];
     $env = new Env();
     $this->assertSame("development", $env->get("APP_ENV"));
     $this->assertNull($env->get("NON_EXISTING"));
     $this->assertSame("production", $env->get("NON_EXISTING_2", "production"));
 }
コード例 #2
0
ファイル: Request.php プロジェクト: Nkelliny/Framework
 /**
  * Get a value from $_ENV param for the given $key.
  * If key doesn't not exist, $value will be returned and assigned under that key.
  *
  * @param string $key   Key for which you wish to get the value.
  * @param mixed  $value Default value that will be returned if $key doesn't exist.
  *
  * @return mixed Value of the given $key.
  */
 public function env($key = null, $value = null)
 {
     return $this->isNull($key) ? $this->env->getAll() : $this->env->get($key, $value);
 }