Skip to content

Commit

Permalink
Json: added decodeFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 28, 2022
1 parent 70b3543 commit cb92bc6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Utils/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit cb92bc6

Please sign in to comment.