From bb9fc73885ab80faa324ce6dd275e766b28221d9 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 5 Apr 2015 23:54:05 +0200 Subject: [PATCH 1/1] Added isGetRequestMethod(), isHeadRequestMethod() and isPostRequestMethod(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../interfaces/request/class_Requestable.php | 21 ++++++++++++ .../request/console/class_ConsoleRequest.php | 33 +++++++++++++++++++ .../main/request/html/class_HtmlRequest.php | 30 +++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/inc/classes/interfaces/request/class_Requestable.php b/inc/classes/interfaces/request/class_Requestable.php index 3693d94a..5a9ef492 100644 --- a/inc/classes/interfaces/request/class_Requestable.php +++ b/inc/classes/interfaces/request/class_Requestable.php @@ -77,6 +77,27 @@ interface Requestable extends FrameworkInterface { * @return $cookieValue Value of cookie or null if not found */ function readCookie ($cookieName); + + /** + * Checks if the request method is GET. + * + * @return $isGet Whether the request method is GET + */ + function isGetRequestMethod (); + + /** + * Checks if the request method is HEAD. + * + * @return $isHead Whether the request method is HEAD + */ + function isHeadRequestMethod (); + + /** + * Checks if the request method is POST. + * + * @return $isPost Whether the request method is POST + */ + function isPostRequestMethod (); } // [EOF] diff --git a/inc/classes/main/request/console/class_ConsoleRequest.php b/inc/classes/main/request/console/class_ConsoleRequest.php index eba7b74d..c5e070ed 100644 --- a/inc/classes/main/request/console/class_ConsoleRequest.php +++ b/inc/classes/main/request/console/class_ConsoleRequest.php @@ -118,6 +118,39 @@ class ConsoleRequest extends BaseRequest implements Requestable { // There are no cookies on console throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION); } + + /** + * Checks if the request method is GET. + * + * @return $isGet Whether the request method is GET + * @throws UnsupportedOperationException This method should never be called + */ + public function isGetRequestMethod () { + // Not support method + throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * Checks if the request method is HEAD. + * + * @return $isHead Whether the request method is HEAD + * @throws UnsupportedOperationException This method should never be called + */ + public function isHeadRequestMethod () { + // Not support method + throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * Checks if the request method is POST. + * + * @return $isPost Whether the request method is POST + * @throws UnsupportedOperationException This method should never be called + */ + public function isPostRequestMethod () { + // Not support method + throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION); + } } // [EOF] diff --git a/inc/classes/main/request/html/class_HtmlRequest.php b/inc/classes/main/request/html/class_HtmlRequest.php index 63ccd826..e808c710 100644 --- a/inc/classes/main/request/html/class_HtmlRequest.php +++ b/inc/classes/main/request/html/class_HtmlRequest.php @@ -49,6 +49,36 @@ class HtmlRequest extends BaseRequest implements Requestable { return $requestInstance; } + /** + * Checks if the request method is GET. + * + * @return $isGet Whether the request method is GET + */ + public function isGetRequestMethod () { + // Check it + return ($this->getRequestMethod() == 'GET'); + } + + /** + * Checks if the request method is HEAD. + * + * @return $isHead Whether the request method is HEAD + */ + public function isHeadRequestMethod () { + // Check it + return ($this->getRequestMethod() == 'HEAD'); + } + + /** + * Checks if the request method is POST. + * + * @return $isPost Whether the request method is POST + */ + public function isPostRequestMethod () { + // Check it + return ($this->getRequestMethod() == 'POST'); + } + /** * Prepares the HTML request data for usage by currently copying * $_REQUEST into a private attribute. Later on we can add more -- 2.39.5