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 | * Get some data by pretty name |
||
34 | * |
||
35 | * @param string $name name for access |
||
36 | * @param mixed $default used for non safe request, if we dont find answer |
||
37 | * @return mixed |
||
38 | * @throws \Exception |
||
39 | */ |
||
40 | public function get(string $name, $default = null) |
||
44 | |||
45 | /** |
||
46 | * Magic proxy call to data |
||
47 | * @param string $name |
||
48 | * @param array $arguments |
||
49 | * @return mixed |
||
50 | */ |
||
51 | public function __call($name, $arguments) |
||
56 | |||
57 | /** |
||
58 | * Magic isset |
||
59 | * @param string $name |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function __isset($name) |
||
66 | |||
67 | /** |
||
68 | * Magic getter, sugar for get() |
||
69 | * @param string $name |
||
70 | * @return mixed |
||
71 | */ |
||
72 | public function __get($name) |
||
76 | |||
77 | /** |
||
78 | * Get count of data fields, just sugar for data methods |
||
79 | * |
||
80 | * @return int |
||
81 | */ |
||
82 | public function count(): int |
||
86 | |||
87 | /** |
||
88 | * Json serialise data - here just data object/array |
||
89 | * @return type |
||
90 | */ |
||
91 | public function jsonSerialize() |
||
95 | |||
96 | /** |
||
97 | * Get iterator |
||
98 | * |
||
99 | * @return \Traversable |
||
100 | */ |
||
101 | public function getIterator(): \Traversable |
||
105 | |||
106 | /** |
||
107 | * Get keys list |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | public function keys(): array |
||
115 | |||
116 | /** |
||
117 | * Sugar for array access is_set |
||
118 | * |
||
119 | * @param type $offset |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function offsetExists($offset): bool |
||
126 | |||
127 | /** |
||
128 | * Sugar ArrayAccess getter |
||
129 | * |
||
130 | * @param type $offset |
||
131 | * @return type |
||
132 | */ |
||
133 | public function offsetGet($offset) |
||
137 | |||
138 | public function fieldLabel(string $key): string |
||
146 | |||
147 | public function title(): string |
||
157 | |||
158 | public function fieldsInfo(): array |
||
170 | |||
171 | /** |
||
172 | * Dummy method for interface only |
||
173 | * |
||
174 | * @param mixed $offset |
||
175 | * @param mixed $value |
||
176 | * @return void |
||
177 | * @throws \RuntimeException |
||
178 | */ |
||
179 | public function offsetSet($offset, $value): void |
||
183 | |||
184 | /** |
||
185 | * Dummy method for interface only |
||
186 | * |
||
187 | * @param mixed $offset |
||
188 | * @return void |
||
189 | * @throws type |
||
190 | */ |
||
191 | public function offsetUnset($offset): void |
||
195 | |||
196 | } |