From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../Icinga/Exception/Http/BaseHttpException.php | 73 ++++++++++++++++++++++ .../Exception/Http/HttpBadRequestException.php | 12 ++++ library/Icinga/Exception/Http/HttpException.php | 25 ++++++++ .../Exception/Http/HttpExceptionInterface.php | 21 +++++++ .../Http/HttpMethodNotAllowedException.php | 36 +++++++++++ .../Exception/Http/HttpNotFoundException.php | 12 ++++ 6 files changed, 179 insertions(+) create mode 100644 library/Icinga/Exception/Http/BaseHttpException.php create mode 100644 library/Icinga/Exception/Http/HttpBadRequestException.php create mode 100644 library/Icinga/Exception/Http/HttpException.php create mode 100644 library/Icinga/Exception/Http/HttpExceptionInterface.php create mode 100644 library/Icinga/Exception/Http/HttpMethodNotAllowedException.php create mode 100644 library/Icinga/Exception/Http/HttpNotFoundException.php (limited to 'library/Icinga/Exception/Http') diff --git a/library/Icinga/Exception/Http/BaseHttpException.php b/library/Icinga/Exception/Http/BaseHttpException.php new file mode 100644 index 0000000..cad41c6 --- /dev/null +++ b/library/Icinga/Exception/Http/BaseHttpException.php @@ -0,0 +1,73 @@ +statusCode; + } + + /** + * Set this exception's HTTP response headers + * + * @param array $headers + * + * @return $this + */ + public function setHeaders(array $headers) + { + $this->headers = $headers; + return $this; + } + + /** + * Set/Add a HTTP response header + * + * @param string $name + * @param string $value + * + * @return $this + */ + public function setHeader($name, $value) + { + $this->headers[$name] = $value; + return $this; + } + + /** + * Return this exception's HTTP response headers + * + * @return array An array where each key is a header name and the value its value + */ + public function getHeaders() + { + return $this->headers ?: array(); + } +} diff --git a/library/Icinga/Exception/Http/HttpBadRequestException.php b/library/Icinga/Exception/Http/HttpBadRequestException.php new file mode 100644 index 0000000..004eabd --- /dev/null +++ b/library/Icinga/Exception/Http/HttpBadRequestException.php @@ -0,0 +1,12 @@ +statusCode = (int) $statusCode; + + $args = func_get_args(); + array_shift($args); + call_user_func_array('parent::__construct', $args); + } +} diff --git a/library/Icinga/Exception/Http/HttpExceptionInterface.php b/library/Icinga/Exception/Http/HttpExceptionInterface.php new file mode 100644 index 0000000..c5e0cc7 --- /dev/null +++ b/library/Icinga/Exception/Http/HttpExceptionInterface.php @@ -0,0 +1,21 @@ +getHeaders(); + return isset($headers['Allow']) ? $headers['Allow'] : null; + } + + /** + * Set the allowed HTTP methods + * + * @param string $allowedMethods + * + * @return $this + */ + public function setAllowedMethods($allowedMethods) + { + $this->setHeader('Allow', (string) $allowedMethods); + return $this; + } +} diff --git a/library/Icinga/Exception/Http/HttpNotFoundException.php b/library/Icinga/Exception/Http/HttpNotFoundException.php new file mode 100644 index 0000000..eb91d63 --- /dev/null +++ b/library/Icinga/Exception/Http/HttpNotFoundException.php @@ -0,0 +1,12 @@ +