| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | namespace ngatngay; |
| 6: | |
| 7: | class json |
| 8: | { |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | public static function encode(...$args) { |
| 14: | return json_encode(...$args); |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | public static function decode($data, ...$args) { |
| 23: | $assoc = true; |
| 24: | if (count($args) > 0) { |
| 25: | $assoc = $args[0]; |
| 26: | } |
| 27: | return json5_decode($data, $assoc, ...array_slice($args, 1)); |
| 28: | } |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public static function encode_file($file, ...$args) { |
| 36: | return file_put_contents($file, json_encode(...$args)); |
| 37: | } |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | public static function decode_file($file, ...$args) { |
| 45: | $assoc = true; |
| 46: | if (count($args) > 0) { |
| 47: | $assoc = $args[0]; |
| 48: | } |
| 49: | return json5_decode(file_get_contents($file), $assoc, ...array_slice($args, 1)); |
| 50: | } |
| 51: | } |
| 52: | |