diff options
author | minstel <minstel@yandex.ru> | 2016-10-21 01:18:26 +0300 |
---|---|---|
committer | minstel <minstel@yandex.ru> | 2016-10-21 01:18:26 +0300 |
commit | e465455424a7e1a44265bffd95589242e3642835 (patch) | |
tree | 8ef84f414683662dfcc751e67f257c6835e6ccfe /src | |
parent | 298f38a4347b8b29e3d145f8b5a0a24ea5775640 (diff) | |
download | controller-e465455424a7e1a44265bffd95589242e3642835.zip controller-e465455424a7e1a44265bffd95589242e3642835.tar.gz controller-e465455424a7e1a44265bffd95589242e3642835.tar.bz2 |
Controller request method methods
Diffstat (limited to 'src')
-rw-r--r-- | src/Controller.php | 98 |
1 files changed, 81 insertions, 17 deletions
diff --git a/src/Controller.php b/src/Controller.php index ddec2c0..c480a07 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -111,25 +111,89 @@ abstract class Controller } /** - * Check if response is 4xx or 5xx error - * - * @return boolean - */ - public function isError() - { - return $this->isClientError() || $this->isServerError(); - } - - /** - * Get status code of response - * - * @return int - */ - protected function getResponseStatusCode() - { + * Check if response is 4xx or 5xx error + * + * @return boolean + */ + 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'; + } + + /** + * Get status code of response + * + * @return int + */ + protected function getResponseStatusCode() + { $response = $this->getResponse(); return $response ? $response->getStatusCode() : 0; - } + } + + /** + * Get method of request + * + * @return string + */ + protected function getRequestMethod() + { + $request = $this->getRequest(); + + return $request ? $request->getMethod() : ''; + } } |