Json: allow null/false
This commit is contained in:
parent
0b341c6db1
commit
4e327ed54d
|
@ -6,11 +6,22 @@ use Icinga\Module\Director\Exception\JsonEncodeException;
|
|||
|
||||
class Json
|
||||
{
|
||||
public static function encode($string)
|
||||
public static function encode($mixed, $flags = null)
|
||||
{
|
||||
$result = json_encode($string);
|
||||
$result = json_encode($mixed, $flags);
|
||||
|
||||
if ($result === false) {
|
||||
if ($result === false && json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw JsonEncodeException::forLastJsonError();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function decode($string)
|
||||
{
|
||||
$result = json_decode($string);
|
||||
|
||||
if ($result === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw JsonEncodeException::forLastJsonError();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue