1: <?php
2: /**
3: * @author Jefferson González
4: * @license MIT
5: * @link http://github.com/peg-org/peg-custom Source code.
6: */
7:
8: namespace Peg\Custom\Utilities;
9:
10: /**
11: * Encapsulates json functions to provide indentation
12: * as conversion from json to plain php arrays.
13: */
14: class Json
15: {
16:
17: // Disable constructor
18: private function __construct(){}
19:
20: /**
21: * Equivalent of json_encode function but output pretty printed
22: * json format to make it possible to edit the output manually.
23: * @param array $data
24: * @return string
25: */
26: public static function Encode($data)
27: {
28: return json_encode($data, JSON_PRETTY_PRINT);
29: }
30:
31: /**
32: * Equivalent to json_decode for json but with associative turned on.
33: * This function retreive json objects as associative array.
34: * @param string $data Json encoded data.
35: * @return array
36: */
37: public static function Decode($data)
38: {
39: return json_decode($data, true);
40: }
41:
42: }