diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Controller.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/Controller.php b/src/Controller.php index 93853d1..057653e 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -337,6 +337,58 @@ abstract class Controller public function isError() { return $this->isClientError() || $this->isServerError(); + } + + /** + * Check if request is GET request + * + * @return boolean + */ + public function isGetRequest() + { + $method = $this->getRequestMethod(); + + return !$method || $method === 'GET'; + } + + /** + * Check if request is POST request + * + * @return boolean + */ + public function isPostRequest() + { + return $this->getRequestMethod() === 'POST'; + } + + /** + * Check if request is PUT request + * + * @return boolean + */ + public function isPutRequest() + { + return $this->getRequestMethod() === 'PUT'; + } + + /** + * Check if request is DELETE request + * + * @return boolean + */ + public function isDeleteRequest() + { + return $this->getRequestMethod() === 'DELETE'; + } + + /** + * Check if request is HEAD request + * + * @return boolean + */ + public function isHeadRequest() + { + return $this->getRequestMethod() === 'HEAD'; } /** @@ -451,5 +503,17 @@ abstract class Controller { return array_search($format, $this->contentFormats) ?: $format; } + + /** + * Get method of request + * + * @return string + */ + protected function getRequestMethod() + { + $request = $this->getRequest(); + + return $request ? $request->getMethod() : ''; + } } |