Skip to content

Commit

Permalink
ImportsourceHookTable: show malformed data...
Browse files Browse the repository at this point in the history
...plus some namespacing/cleanup
  • Loading branch information
Thomas-Gelf committed Apr 4, 2019
1 parent 3479c4a commit 659a03d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions library/Director/Core/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
22 changes: 11 additions & 11 deletions library/Director/Exception/JsonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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];
}
}
Expand All @@ -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];
}
}
Expand Down
7 changes: 5 additions & 2 deletions library/Director/Web/Table/ImportsourceHookTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 659a03d

Please sign in to comment.