Skip to content

Commit

Permalink
Added getEnv method
Browse files Browse the repository at this point in the history
  • Loading branch information
eldadfux committed Jun 18, 2020
1 parent b480f9d commit c6d43bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ public function error($callback)
return $this;
}

/**
* Get env var
*
* Method for querying env varialbles. If $key is not found $default value will be returned.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function getEnv($key, $default = null)
{
return (isset($_SERVER[$key])) ? $_SERVER[$key] : $default;
}

/**
* Get Mode
*
Expand Down
9 changes: 9 additions & 0 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public function testIsMode() {
$this->assertEquals(true, $app->isStage());
}

public function testGetEnv()
{
// Mock
$_SERVER['key'] = 'value';

$this->assertEquals($this->app->getEnv('key'), 'value');
$this->assertEquals($this->app->getEnv('unknown', 'test'), 'test');
}

public function tearDown()
{
$this->view = null;
Expand Down

0 comments on commit c6d43bc

Please sign in to comment.