1 | <?php |
||
13 | class Structure extends ArrayObject { |
||
14 | |||
15 | /** |
||
16 | * An Structure can wrap a StdClass, an array or an object from a JSON encoded string. |
||
17 | * |
||
18 | * This class is useful for wrapping API responses and access their properties in |
||
19 | * an easy way. |
||
20 | * |
||
21 | * @param mixed $input The object/array/json_encoded object to wrap |
||
22 | * @param boolean $deep Wrap also deep branches as Objects |
||
23 | */ |
||
24 | public function __construct($input=[], $deep=true){ |
||
41 | |||
42 | /** |
||
43 | * ArrayObject::offsetSet |
||
44 | */ |
||
45 | public function offsetSet($key, $value){ |
||
51 | |||
52 | /** |
||
53 | * ArrayObject::offsetGet |
||
54 | */ |
||
55 | public function offsetGet($key){ |
||
59 | |||
60 | /** |
||
61 | * Emulate object methods |
||
62 | */ |
||
63 | public function __call($method, $args){ |
||
70 | |||
71 | /** |
||
72 | * If casted as a string, return a JSON rappresentation of the wrapped payload |
||
73 | * @return string |
||
74 | */ |
||
75 | public function __toString(){ |
||
78 | |||
79 | /** |
||
80 | * Dot-Notation Array Path Resolver |
||
81 | * @param string $path The dot-notation path |
||
82 | * @param array $root The array to navigate |
||
83 | * @return mixed The pointed value |
||
84 | */ |
||
85 | |||
86 | public static function fetch($path, $root) { |
||
101 | |||
102 | public static function create($class, $args = null){ |
||
105 | |||
106 | public static function canBeString($var) { |
||
109 | |||
110 | } |
||
111 |