summaryrefslogtreecommitdiffstats
path: root/library/Director/Exception
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
commitcd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Exception
parentInitial commit. (diff)
downloadicingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz
icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Exception')
-rw-r--r--library/Director/Exception/DuplicateKeyException.php9
-rw-r--r--library/Director/Exception/JsonEncodeException.php7
-rw-r--r--library/Director/Exception/JsonException.php55
-rw-r--r--library/Director/Exception/NestingError.php9
4 files changed, 80 insertions, 0 deletions
diff --git a/library/Director/Exception/DuplicateKeyException.php b/library/Director/Exception/DuplicateKeyException.php
new file mode 100644
index 0000000..a9cba65
--- /dev/null
+++ b/library/Director/Exception/DuplicateKeyException.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Icinga\Module\Director\Exception;
+
+use Icinga\Exception\IcingaException;
+
+class DuplicateKeyException extends IcingaException
+{
+}
diff --git a/library/Director/Exception/JsonEncodeException.php b/library/Director/Exception/JsonEncodeException.php
new file mode 100644
index 0000000..7db2f77
--- /dev/null
+++ b/library/Director/Exception/JsonEncodeException.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace Icinga\Module\Director\Exception;
+
+class JsonEncodeException extends JsonException
+{
+}
diff --git a/library/Director/Exception/JsonException.php b/library/Director/Exception/JsonException.php
new file mode 100644
index 0000000..dad848d
--- /dev/null
+++ b/library/Director/Exception/JsonException.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Icinga\Module\Director\Exception;
+
+use Icinga\Exception\IcingaException;
+
+class JsonException extends IcingaException
+{
+ public static function forLastJsonError($msg = null)
+ {
+ if ($msg === null) {
+ return new static(static::getJsonErrorMessage(\json_last_error()));
+ } else {
+ return new static($msg . ': ' . static::getJsonErrorMessage(\json_last_error()));
+ }
+ }
+
+ public static function getJsonErrorMessage($code)
+ {
+ $map = [
+ JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
+ JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
+ JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
+ JSON_ERROR_SYNTAX => 'JSON Syntax error',
+ JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
+ ];
+ if (\array_key_exists($code, $map)) {
+ return $map[$code];
+ }
+
+ if (PHP_VERSION_ID >= 50500) {
+ $map = [
+ JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded',
+ JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded',
+ JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given',
+ ];
+ if (\array_key_exists($code, $map)) {
+ return $map[$code];
+ }
+ }
+
+ if (PHP_VERSION_ID >= 70000) {
+ $map = [
+ JSON_ERROR_INVALID_PROPERTY_NAME => 'A property name that cannot be encoded was given',
+ JSON_ERROR_UTF16 => 'Malformed UTF-16 characters, possibly incorrectly encoded',
+ ];
+
+ if (\array_key_exists($code, $map)) {
+ return $map[$code];
+ }
+ }
+
+ return 'An error occured when parsing a JSON string';
+ }
+}
diff --git a/library/Director/Exception/NestingError.php b/library/Director/Exception/NestingError.php
new file mode 100644
index 0000000..bc191aa
--- /dev/null
+++ b/library/Director/Exception/NestingError.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Icinga\Module\Director\Exception;
+
+use Icinga\Exception\IcingaException;
+
+class NestingError extends IcingaException
+{
+}