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/AlreadyExistsException.php | 11 +++ .../Icinga/Exception/AuthenticationException.php | 11 +++ library/Icinga/Exception/ConfigurationError.php | 12 +++ .../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 +++ library/Icinga/Exception/IcingaException.php | 107 +++++++++++++++++++++ .../Icinga/Exception/InvalidPropertyException.php | 11 +++ .../Icinga/Exception/Json/JsonDecodeException.php | 11 +++ .../Icinga/Exception/Json/JsonEncodeException.php | 11 +++ library/Icinga/Exception/Json/JsonException.php | 13 +++ .../Icinga/Exception/MissingParameterException.php | 40 ++++++++ library/Icinga/Exception/NotFoundError.php | 8 ++ library/Icinga/Exception/NotImplementedError.php | 12 +++ library/Icinga/Exception/NotReadableError.php | 8 ++ library/Icinga/Exception/NotWritableError.php | 8 ++ library/Icinga/Exception/ProgrammingError.php | 12 +++ library/Icinga/Exception/QueryException.php | 11 +++ library/Icinga/Exception/StatementException.php | 8 ++ .../Icinga/Exception/SystemPermissionException.php | 11 +++ 23 files changed, 484 insertions(+) create mode 100644 library/Icinga/Exception/AlreadyExistsException.php create mode 100644 library/Icinga/Exception/AuthenticationException.php create mode 100644 library/Icinga/Exception/ConfigurationError.php 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 create mode 100644 library/Icinga/Exception/IcingaException.php create mode 100644 library/Icinga/Exception/InvalidPropertyException.php create mode 100644 library/Icinga/Exception/Json/JsonDecodeException.php create mode 100644 library/Icinga/Exception/Json/JsonEncodeException.php create mode 100644 library/Icinga/Exception/Json/JsonException.php create mode 100644 library/Icinga/Exception/MissingParameterException.php create mode 100644 library/Icinga/Exception/NotFoundError.php create mode 100644 library/Icinga/Exception/NotImplementedError.php create mode 100644 library/Icinga/Exception/NotReadableError.php create mode 100644 library/Icinga/Exception/NotWritableError.php create mode 100644 library/Icinga/Exception/ProgrammingError.php create mode 100644 library/Icinga/Exception/QueryException.php create mode 100644 library/Icinga/Exception/StatementException.php create mode 100644 library/Icinga/Exception/SystemPermissionException.php (limited to 'library/Icinga/Exception') diff --git a/library/Icinga/Exception/AlreadyExistsException.php b/library/Icinga/Exception/AlreadyExistsException.php new file mode 100644 index 0000000..d70c58f --- /dev/null +++ b/library/Icinga/Exception/AlreadyExistsException.php @@ -0,0 +1,11 @@ +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 @@ +newInstanceArgs($args); + } + + /** + * Return the given exception formatted as one-liner + * + * The format used is: %class% in %path%:%line% with message: %message% + * + * @param Exception $exception + * + * @return string + */ + public static function describe(Exception $exception) + { + return sprintf( + '%s in %s:%d with message: %s', + get_class($exception), + $exception->getFile(), + $exception->getLine(), + $exception->getMessage() + ); + } + + /** + * Return the same as {@link Exception::getTraceAsString()} for the given exception, + * but show only the types of scalar arguments + * + * @param Exception $exception + * + * @return string + */ + public static function getConfidentialTraceAsString(Exception $exception) + { + $trace = array(); + + foreach ($exception->getTrace() as $index => $frame) { + $trace[] = isset($frame['file']) + ? "#{$index} {$frame['file']}({$frame['line']}): " + : "#{$index} [internal function]: "; + + if (isset($frame['class'])) { + $trace[] = $frame['class']; + } + + if (isset($frame['type'])) { + $trace[] = $frame['type']; + } + + $trace[] = "{$frame['function']}("; + + if (isset($frame['args'])) { + $args = array(); + foreach ($frame['args'] as $arg) { + $type = gettype($arg); + $args[] = $type === 'object' ? 'Object(' . get_class($arg) . ')' : ucfirst($type); + } + + $trace[] = implode(', ', $args); + } + $trace[] = ")\n"; + } + + $trace[] = '#' . ($index + 1) . ' {main}'; + + return implode($trace); + } +} diff --git a/library/Icinga/Exception/InvalidPropertyException.php b/library/Icinga/Exception/InvalidPropertyException.php new file mode 100644 index 0000000..e7bcf32 --- /dev/null +++ b/library/Icinga/Exception/InvalidPropertyException.php @@ -0,0 +1,11 @@ +parameter; + } + + /** + * Set the name of the missing parameter + * + * @param string $name + * + * @return $this + */ + public function setParameter($name) + { + $this->parameter = (string) $name; + return $this; + } +} diff --git a/library/Icinga/Exception/NotFoundError.php b/library/Icinga/Exception/NotFoundError.php new file mode 100644 index 0000000..74e6941 --- /dev/null +++ b/library/Icinga/Exception/NotFoundError.php @@ -0,0 +1,8 @@ +