From 659a03dd03ccbf359ec16ee1f0821446b4dc3666 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 4 Apr 2019 13:11:39 +0200 Subject: [PATCH] ImportsourceHookTable: show malformed data... ...plus some namespacing/cleanup --- library/Director/Core/Json.php | 4 ++-- library/Director/Exception/JsonException.php | 22 +++++++++---------- .../Web/Table/ImportsourceHookTable.php | 7 ++++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/library/Director/Core/Json.php b/library/Director/Core/Json.php index fc3288c69..b1006c883 100644 --- a/library/Director/Core/Json.php +++ b/library/Director/Core/Json.php @@ -8,7 +8,7 @@ class Json { public static function encode($mixed, $flags = null) { - $result = json_encode($mixed, $flags); + $result = \json_encode($mixed, $flags); if ($result === false && json_last_error() !== JSON_ERROR_NONE) { throw JsonEncodeException::forLastJsonError(); @@ -19,7 +19,7 @@ public static function encode($mixed, $flags = null) public static function decode($string) { - $result = json_decode($string); + $result = \json_decode($string); if ($result === null && json_last_error() !== JSON_ERROR_NONE) { throw JsonEncodeException::forLastJsonError(); diff --git a/library/Director/Exception/JsonException.php b/library/Director/Exception/JsonException.php index 0c0f0ccd1..eec114109 100644 --- a/library/Director/Exception/JsonException.php +++ b/library/Director/Exception/JsonException.php @@ -9,24 +9,24 @@ class JsonException extends IcingaException public static function forLastJsonError($msg = null) { if ($msg === null) { - return new static(static::getJsonErrorMessage(json_last_error())); + return new static(static::getJsonErrorMessage(\json_last_error())); } else { - $args = func_get_args(); - $args[0] = $msg . ': ' . static::getJsonErrorMessage(json_last_error()); - return call_user_func_array('static::__construct', $args); + $args = \func_get_args(); + $args[0] = $msg . ': ' . static::getJsonErrorMessage(\json_last_error()); + return \call_user_func_array('static::__construct', $args); } } 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_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 => 'Syntax error', - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' + JSON_ERROR_SYNTAX => 'JSON Syntax error', + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' ]; - if (array_key_exists($code, $map)) { + if (\array_key_exists($code, $map)) { return $map[$code]; } @@ -36,7 +36,7 @@ public static function getJsonErrorMessage($code) 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)) { + if (\array_key_exists($code, $map)) { return $map[$code]; } } @@ -47,7 +47,7 @@ public static function getJsonErrorMessage($code) JSON_ERROR_UTF16 => 'Malformed UTF-16 characters, possibly incorrectly encoded', ]; - if (array_key_exists($code, $map)) { + if (\array_key_exists($code, $map)) { return $map[$code]; } } diff --git a/library/Director/Web/Table/ImportsourceHookTable.php b/library/Director/Web/Table/ImportsourceHookTable.php index 2e1fad0f4..6a48953aa 100644 --- a/library/Director/Web/Table/ImportsourceHookTable.php +++ b/library/Director/Web/Table/ImportsourceHookTable.php @@ -65,12 +65,15 @@ public function renderRow($row) if ($row === null) { return null; } + if (\is_array($row)) { + $row = (object) $row; + } $tr = $this::tr(); foreach ($this->getColumnsToBeRendered() as $column) { $td = $this::td(); - if (property_exists($row, $column)) { - if (is_string($row->$column) || $row->$column instanceof ValidHtml) { + if (\property_exists($row, $column)) { + if (\is_string($row->$column) || $row->$column instanceof ValidHtml) { $td->setContent($row->$column); } else { $html = Html::tag('pre', null, PlainObjectRenderer::render($row->$column));