1 | <?php |
||
22 | class Meta implements MetaInterface |
||
23 | { |
||
24 | /** |
||
25 | * Original Meta values (json|array|object). |
||
26 | * |
||
27 | * @var mixed |
||
28 | */ |
||
29 | protected $values; |
||
30 | |||
31 | /** |
||
32 | * @var Context |
||
33 | */ |
||
34 | protected $context; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $configuration; |
||
40 | |||
41 | /** |
||
42 | * Create Meta class from provided configuration and values. |
||
43 | * |
||
44 | * @param Context $context |
||
45 | * @param string|array|object $values |
||
46 | * @param array $configuration |
||
47 | */ |
||
48 | public function __construct(Context $context, $values, $configuration) |
||
64 | |||
65 | /** |
||
66 | * Use to_string property from configuration if provided, json with exposed properties otherwise. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function __toString() |
||
82 | |||
83 | /** |
||
84 | * @param string $name |
||
85 | * @param mixed $value |
||
86 | */ |
||
87 | public function __set($name, $value) |
||
103 | |||
104 | private function getValueOrMeta($value) |
||
112 | |||
113 | /** |
||
114 | * @return array|object|string |
||
115 | */ |
||
116 | public function getValues() |
||
120 | |||
121 | /** |
||
122 | * @return array |
||
123 | */ |
||
124 | public function getConfiguration() |
||
128 | |||
129 | /** |
||
130 | * @param array $configuration |
||
131 | */ |
||
132 | public function setConfiguration($configuration) |
||
136 | |||
137 | /** |
||
138 | * @return Context |
||
139 | */ |
||
140 | public function getContext() |
||
144 | |||
145 | /** |
||
146 | * Fill Meta from array. Array must have property names and keys. |
||
147 | * |
||
148 | * @param array $values Array with properyy names as keys |
||
149 | * @param array $configuration |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | private function fillFromArray(array $values, $configuration) |
||
161 | |||
162 | /** |
||
163 | * Fill Meta from object. Object must have public getters for properties. |
||
164 | * |
||
165 | * @param mixed $values Object with public getters for properties |
||
166 | * @param $configuration |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | private function fillFromObject($values, $configuration) |
||
181 | |||
182 | /** |
||
183 | * Get exposed properties (according to configuration) from provided values. |
||
184 | * |
||
185 | * @param array $values |
||
186 | * @param $configuration |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | private function getExposedProperties(array $values = [], $configuration = []) |
||
203 | |||
204 | /** |
||
205 | * Check if string is JSON. |
||
206 | * |
||
207 | * @param string |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | private function isJson($string) |
||
217 | |||
218 | /** |
||
219 | * Don't serialize values, context and configuration. |
||
220 | * |
||
221 | * @return array |
||
222 | */ |
||
223 | public function __sleep() |
||
231 | } |
||
232 |