1 | <?php |
||
12 | class DataWrapper implements ModelInterface, \IteratorAggregate, \ArrayAccess |
||
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) |
||
31 | |||
32 | /** |
||
33 | * Magic proxy call to data |
||
34 | * @param string $name |
||
35 | * @param array $arguments |
||
36 | * @return mixed |
||
37 | */ |
||
38 | public function __call($name, $arguments) |
||
43 | |||
44 | /** |
||
45 | * Magic isset |
||
46 | * @param string $name |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function __isset($name) |
||
53 | |||
54 | /** |
||
55 | * Get some data by pretty name |
||
56 | * |
||
57 | * @param string $name name for access |
||
58 | * @return mixed |
||
59 | * @throws \Exception |
||
60 | */ |
||
61 | public function __get($name) |
||
65 | |||
66 | /** |
||
67 | * Get count of data fields, just sugar for data methods |
||
68 | * |
||
69 | * @return int |
||
70 | */ |
||
71 | public function count(): int |
||
75 | |||
76 | /** |
||
77 | * Json serialise data - here just data object/array |
||
78 | * @return object|array |
||
79 | */ |
||
80 | public function jsonSerialize() |
||
84 | |||
85 | /** |
||
86 | * Get iterator |
||
87 | * |
||
88 | * @return \Traversable |
||
89 | */ |
||
90 | public function getIterator(): \Traversable |
||
94 | |||
95 | /** |
||
96 | * Get keys list |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | public function keys(): array |
||
104 | |||
105 | /** |
||
106 | * Sugar for array access is_set |
||
107 | * |
||
108 | * @param type $offset |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function offsetExists($offset): bool |
||
115 | |||
116 | /** |
||
117 | * Sugar ArrayAccess getter |
||
118 | * |
||
119 | * @param type $offset |
||
120 | * @return type |
||
121 | */ |
||
122 | public function offsetGet($offset) |
||
126 | |||
127 | public function fieldLabel(string $key): string |
||
135 | |||
136 | public function title(): string |
||
146 | |||
147 | public function fieldsInfo(): array |
||
159 | |||
160 | /** |
||
161 | * Magic setter for ArrayAccess |
||
162 | * |
||
163 | * @param mixed $offset |
||
164 | * @param mixed $value |
||
165 | * @return void |
||
166 | */ |
||
167 | public function offsetSet($offset, $value): void |
||
175 | |||
176 | /** |
||
177 | * Magic unset for ArrayAccess |
||
178 | * |
||
179 | * @param mixed $offset |
||
180 | * @return void |
||
181 | */ |
||
182 | public function offsetUnset($offset): void |
||
186 | |||
187 | /** |
||
188 | * Magic unset |
||
189 | * |
||
190 | * @param string $name |
||
191 | * @return void |
||
192 | */ |
||
193 | public function __unset($name) : void |
||
201 | |||
202 | } |