Skip to content

Commit

Permalink
Merge branch 'joelhy-feat/getServerParam' into 3.x
Browse files Browse the repository at this point in the history
Closes #1965
  • Loading branch information
akrabat committed Aug 14, 2016
2 parents a4373da + 0308319 commit 54a8bb5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,22 @@ public function getServerParams()
return $this->serverParams;
}

/**
* Retrieve a server parameter.
*
* Note: This method is not part of the PSR-7 standard.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function getServerParam($key, $default = null)
{
$serverParams = $this->getServerParams();

return isset($serverParams[$key]) ? $serverParams[$key] : $default;
}

/*******************************************************************************
* Attributes
******************************************************************************/
Expand Down
15 changes: 15 additions & 0 deletions tests/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,21 @@ public function testGetServerParams()
}
}

public function testGetServerParam()
{
$shouldBe = 'HTTP/1.1';
$request = $this->requestFactory(['SERVER_PROTOCOL' => 'HTTP/1.1']);

$this->assertEquals($shouldBe, $this->requestFactory()->getServerParam('SERVER_PROTOCOL'));
}

public function testGetServerParamWithDefault()
{
$shouldBe = 'bar';

$this->assertEquals($shouldBe, $this->requestFactory()->getServerParam('HTTP_NOT_EXIST', 'bar'));
}

/*******************************************************************************
* File Params
******************************************************************************/
Expand Down

0 comments on commit 54a8bb5

Please sign in to comment.