Json: implement decodeOptional() for null support

This commit is contained in:
Thomas Gelf 2021-10-05 19:08:36 +02:00
parent c2d7b235a5
commit 654f845e4e
1 changed files with 14 additions and 0 deletions

View File

@ -52,4 +52,18 @@ class Json
return $result;
}
/**
* @param $string
* @return ?string
* @throws JsonEncodeException
*/
public static function decodeOptional($string)
{
if ($string === null) {
return null;
}
return static::decode($string);
}
}