From cb92bc6111dd9648bb45ef579979cd93b6f526c0 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 21 Jan 2022 08:08:02 +0100 Subject: [PATCH] Json: added decodeFile() --- src/Utils/Json.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Utils/Json.php b/src/Utils/Json.php index fab5b6f45..c28d89019 100644 --- a/src/Utils/Json.php +++ b/src/Utils/Json.php @@ -71,4 +71,19 @@ public static function decode(string $json, bool|int $forceArray = false): mixed return $value; } + + + /** + * Converts given JSON file to PHP value. + * @throws JsonException + */ + public static function decodeFile(string $file, bool|int $forceArray = false): mixed + { + if (!is_file($file)) { + throw new Nette\IOException("File '$file' does not exist."); + } + + $input = file_get_contents($file); + return self::decode($input, $forceArray); + } }