1 | <?php |
||
12 | class DataWrapper implements \Countable, \JsonSerializable, \IteratorAggregate |
||
13 | { |
||
14 | use CheckTrait; |
||
15 | |||
16 | protected $data; |
||
17 | protected $safe = true; |
||
18 | |||
19 | /** |
||
20 | * @param mixed $data Data for we access. Array, object etc... |
||
21 | * @param bool $safe if true - Exception for not exist fields |
||
22 | */ |
||
23 | public function __construct($data, bool $safe = true) |
||
28 | |||
29 | /** |
||
30 | * Get some data by pretty name |
||
31 | * |
||
32 | * @param string $name name for access |
||
33 | * @param mixed $default used for non safe request, if we dont find answer |
||
34 | * @return mixed |
||
35 | * @throws \Exception |
||
36 | */ |
||
37 | public function get(string $name, $default = null) |
||
41 | |||
42 | /** |
||
43 | * Magic proxy call to data |
||
44 | * @param string $name |
||
45 | * @param array $arguments |
||
46 | * @return mixed |
||
47 | */ |
||
48 | public function __call($name, $arguments) |
||
53 | |||
54 | /** |
||
55 | * Magic isset |
||
56 | * @param string $name |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function __isset($name) |
||
63 | |||
64 | /** |
||
65 | * Magic getter, sugar for get() |
||
66 | * @param string $name |
||
67 | * @return mixed |
||
68 | */ |
||
69 | public function __get($name) |
||
73 | |||
74 | /** |
||
75 | * Get count of data fields, just sugar for data methods |
||
76 | * |
||
77 | * @return int |
||
78 | */ |
||
79 | public function count(): int |
||
83 | |||
84 | /** |
||
85 | * Json serialise data - here just data object/array |
||
86 | * @return type |
||
87 | */ |
||
88 | public function jsonSerialize() |
||
92 | |||
93 | public function getIterator(): \Traversable |
||
103 | } |