diff options
author | Arnold Daniels <arnold@jasny.net> | 2016-11-17 16:05:57 +0100 |
---|---|---|
committer | Arnold Daniels <arnold@jasny.net> | 2016-11-17 16:05:57 +0100 |
commit | 14bc7de53fda2c44482c7cf46b896cfdd41aa68d (patch) | |
tree | 07fe440ef3febcc8ec9a1e702388cc7bab134b6a /src/Controller.php | |
parent | 75b13f1c90828f9593a68caf1a35c6e12ea9189d (diff) | |
parent | 87578c0415e85b7021a47a334e66c3e843ea9260 (diff) | |
download | controller-14bc7de53fda2c44482c7cf46b896cfdd41aa68d.zip controller-14bc7de53fda2c44482c7cf46b896cfdd41aa68d.tar.gz controller-14bc7de53fda2c44482c7cf46b896cfdd41aa68d.tar.bz2 |
Merge branch 'Minstel-Controller_request_method_methods'
Diffstat (limited to 'src/Controller.php')
-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() : ''; + } } |