From 7033e3b0a56513d4a2297dec6b42c9527938daa8 Mon Sep 17 00:00:00 2001 From: Mark Locker Date: Sun, 22 Dec 2013 11:11:52 +0000 Subject: [PATCH 1/2] Added convenience methods for request type checking. Convenience methods for the four most common request types. --- classes/Kohana/Request.php | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/classes/Kohana/Request.php b/classes/Kohana/Request.php index e5ee71e5d..b3ca518b7 100644 --- a/classes/Kohana/Request.php +++ b/classes/Kohana/Request.php @@ -1328,4 +1328,72 @@ public function post($key = NULL, $value = NULL) return $this; } + /** + * Check to see if the current request is a POST request. + * + * @return bool Whether the request is a POST request or not. + */ + public function is_post() + { + if ($this->method() === HTTP_Request::POST) + { + return TRUE; + } + else + { + return FALSE; + } + } + + /** + * Check to see if the current request is a GET request. + * + * @return bool Whether the request is a GET request or not. + */ + public function is_get() + { + if ($this->method() === HTTP_Request::GET) + { + return TRUE; + } + else + { + return FALSE; + } + } + + /** + * Check to see if the current request is a PUT request. + * + * @return bool Whether the request is a PUT request or not. + */ + public function is_put() + { + if ($this->method() === HTTP_Request::PUT) + { + return TRUE; + } + else + { + return FALSE; + } + } + + /** + * Check to see if the current request is a DELETE request. + * + * @return bool Whether the request is a DELETE request or not. + */ + public function is_delete() + { + if ($this->method() === HTTP_Request::DELETE) + { + return TRUE; + } + else + { + return FALSE; + } + } + } // End Request From e05f6981e7639d387dfc1ca1b7ec03a0819b7248 Mon Sep 17 00:00:00 2001 From: Mark Locker Date: Sun, 22 Dec 2013 20:20:42 +0000 Subject: [PATCH 2/2] Made less verbose. --- classes/Kohana/Request.php | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/classes/Kohana/Request.php b/classes/Kohana/Request.php index b3ca518b7..b7a40f6af 100644 --- a/classes/Kohana/Request.php +++ b/classes/Kohana/Request.php @@ -1335,14 +1335,7 @@ public function post($key = NULL, $value = NULL) */ public function is_post() { - if ($this->method() === HTTP_Request::POST) - { - return TRUE; - } - else - { - return FALSE; - } + return (HTTP_Request::POST === $this->_method); } /** @@ -1352,14 +1345,7 @@ public function is_post() */ public function is_get() { - if ($this->method() === HTTP_Request::GET) - { - return TRUE; - } - else - { - return FALSE; - } + return (HTTP_Request::GET === $this->_method); } /** @@ -1369,14 +1355,7 @@ public function is_get() */ public function is_put() { - if ($this->method() === HTTP_Request::PUT) - { - return TRUE; - } - else - { - return FALSE; - } + return (HTTP_Request::PUT === $this->_method); } /** @@ -1386,14 +1365,7 @@ public function is_put() */ public function is_delete() { - if ($this->method() === HTTP_Request::DELETE) - { - return TRUE; - } - else - { - return FALSE; - } + return (HTTP_Request::DELETE === $this->_method); } } // End Request