From 41a06737438e4694adf4de326895b8c13e293735 Mon Sep 17 00:00:00 2001 From: Martyn Bissett Date: Tue, 5 Jul 2016 17:16:15 +0900 Subject: [PATCH 1/4] Add getCookieParam method --- Slim/Http/Request.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php index 7d5b185dc..68bb97abe 100644 --- a/Slim/Http/Request.php +++ b/Slim/Http/Request.php @@ -669,6 +669,27 @@ public function getContentLength() * 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 + * @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; + } + /** * Retrieve cookies. * From ddc003f6739ec6dc5c7052aecec6196b72d84b79 Mon Sep 17 00:00:00 2001 From: Martyn Bissett Date: Tue, 5 Jul 2016 23:23:28 +0900 Subject: [PATCH 2/4] Add getCookieParam test --- Slim/Http/Request.php | 42 +++++++++++++++++++------------------- tests/Http/RequestTest.php | 7 +++++++ 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php index 68bb97abe..46f1af5bc 100644 --- a/Slim/Http/Request.php +++ b/Slim/Http/Request.php @@ -669,27 +669,6 @@ public function getContentLength() * 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 - * @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; - } - /** * Retrieve cookies. * @@ -705,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 + * @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. * diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php index 995e4f05f..d6229003d 100644 --- a/tests/Http/RequestTest.php +++ b/tests/Http/RequestTest.php @@ -512,6 +512,13 @@ public function testGetContentLengthWithoutHeader() * Cookies ******************************************************************************/ + public function testGetCookieParam() + { + $shouldBe = 'john'; + + $this->assertEquals($shouldBe, $this->requestFactory()->getCookieParam('user')); + } + public function testGetCookieParams() { $shouldBe = [ From d127682dda99243912208ed931cc8cf9b963a36a Mon Sep 17 00:00:00 2001 From: Martyn Bissett Date: Tue, 5 Jul 2016 23:26:51 +0900 Subject: [PATCH 3/4] Add test for getCookieParam with default --- tests/Http/RequestTest.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php index d6229003d..1184b1793 100644 --- a/tests/Http/RequestTest.php +++ b/tests/Http/RequestTest.php @@ -512,12 +512,19 @@ public function testGetContentLengthWithoutHeader() * Cookies ******************************************************************************/ - public function testGetCookieParam() - { - $shouldBe = 'john'; + public function testGetCookieParam() + { + $shouldBe = 'john'; + + $this->assertEquals($shouldBe, $this->requestFactory()->getCookieParam('user')); + } - $this->assertEquals($shouldBe, $this->requestFactory()->getCookieParam('user')); - } + public function testGetCookieParamWithDefault() + { + $shouldBe = 'bar'; + + $this->assertEquals($shouldBe, $this->requestFactory()->getCookieParam('foo', 'bar')); + } public function testGetCookieParams() { From 89a2e47542c21fa39b8ca0af0c76fbb0e480b66d Mon Sep 17 00:00:00 2001 From: Martyn Bissett Date: Fri, 8 Jul 2016 23:02:45 +0900 Subject: [PATCH 4/4] Fix indentation --- Slim/Http/Request.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php index 46f1af5bc..517c452c4 100644 --- a/Slim/Http/Request.php +++ b/Slim/Http/Request.php @@ -684,26 +684,26 @@ 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 - * @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; - } + /** + * 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 + * @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.