diff options
author | minstel <minstel@yandex.ru> | 2016-10-18 00:37:08 +0300 |
---|---|---|
committer | minstel <minstel@yandex.ru> | 2016-10-18 00:37:08 +0300 |
commit | 73c52de728e0bbd5c1a6fa6cb7801de3639734c8 (patch) | |
tree | 4c5f78a1c33129ed1cca7356f9ffec905cd35c32 /src/Controller.php | |
parent | b51040901730a22c990c0f3a52baf8dcbefa0554 (diff) | |
download | controller-73c52de728e0bbd5c1a6fa6cb7801de3639734c8.zip controller-73c52de728e0bbd5c1a6fa6cb7801de3639734c8.tar.gz controller-73c52de728e0bbd5c1a6fa6cb7801de3639734c8.tar.bz2 |
Controller check response status methods
Diffstat (limited to 'src/Controller.php')
-rw-r--r-- | src/Controller.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/Controller.php b/src/Controller.php index 8dfa176..ddec2c0 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -63,5 +63,73 @@ abstract class Controller return $this->run(); } + + /** + * Check if response is 2xx succesful, or empty + * + * @return boolean + */ + public function isSuccessful() + { + $code = $this->getResponseStatusCode(); + + return !$code || ($code >= 200 && $code < 300); + } + + /** + * Check if response is a 3xx redirect + * + * @return boolean + */ + public function isRedirection() + { + $code = $this->getResponseStatusCode(); + + return $code >= 300 && $code < 400; + } + + /** + * Check if response is a 4xx client error + * + * @return boolean + */ + public function isClientError() + { + $code = $this->getResponseStatusCode(); + + return $code >= 400 && $code < 500; + } + + /** + * Check if response is a 5xx redirect + * + * @return boolean + */ + public function isServerError() + { + return $this->getResponseStatusCode() >= 500; + } + + /** + * 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() + { + $response = $this->getResponse(); + + return $response ? $response->getStatusCode() : 0; + } } |