Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,27 @@ public function getCookieParams()
return $this->cookies;
}

/**
* Fetch cookie value from cookies sent by the client to the server.
*
* Note: This method is not part of the PSR-7 standard.
*
* @param $key
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the phpdoc get fixed?

Copy link
Member

@akrabat akrabat Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param null $default
*
* @return null
*/
public function getCookieParam($key, $default = null)
{
$getCookies = $this->getCookieParams();
$result = $default;
if (isset($getCookies[$key])) {
$result = $getCookies[$key];
}

return $result;
}

/**
* Return an instance with the specified cookies.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,20 @@ public function testGetContentLengthWithoutHeader()
* Cookies
******************************************************************************/

public function testGetCookieParam()
{
$shouldBe = 'john';

$this->assertEquals($shouldBe, $this->requestFactory()->getCookieParam('user'));
}

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

$this->assertEquals($shouldBe, $this->requestFactory()->getCookieParam('foo', 'bar'));
}

public function testGetCookieParams()
{
$shouldBe = [
Expand Down