Skip to content

Commit cb92bc6

Browse files
committed
Json: added decodeFile()
1 parent 70b3543 commit cb92bc6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Utils/Json.php

+15
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,19 @@ public static function decode(string $json, bool|int $forceArray = false): mixed
7171

7272
return $value;
7373
}
74+
75+
76+
/**
77+
* Converts given JSON file to PHP value.
78+
* @throws JsonException
79+
*/
80+
public static function decodeFile(string $file, bool|int $forceArray = false): mixed
81+
{
82+
if (!is_file($file)) {
83+
throw new Nette\IOException("File '$file' does not exist.");
84+
}
85+
86+
$input = file_get_contents($file);
87+
return self::decode($input, $forceArray);
88+
}
7489
}

0 commit comments

Comments
 (0)