1 | <?php |
||
22 | class Context implements \ArrayAccess |
||
23 | { |
||
24 | /** |
||
25 | * Array with current page information's. |
||
26 | * |
||
27 | * @var Meta |
||
28 | */ |
||
29 | protected $currentPage; |
||
30 | |||
31 | /** |
||
32 | * Array will all registered meta types. |
||
33 | * |
||
34 | * @var Meta[] |
||
35 | */ |
||
36 | protected $registeredMeta = []; |
||
37 | |||
38 | /** |
||
39 | * Array with available meta configs. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $availableConfigs = []; |
||
44 | |||
45 | /** |
||
46 | * @var Cache |
||
47 | */ |
||
48 | protected $metadataCache; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $configsPath; |
||
54 | |||
55 | /** |
||
56 | * Context constructor. |
||
57 | * |
||
58 | * @param Cache $metadataCache |
||
59 | * @param string $configsPath |
||
60 | */ |
||
61 | public function __construct(Cache $metadataCache, $configsPath = null) |
||
66 | |||
67 | /** |
||
68 | * @return array |
||
69 | */ |
||
70 | public function getAvailableConfigs() |
||
78 | |||
79 | /** |
||
80 | * @param array $configuration |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function addAvailableConfig(array $configuration) |
||
94 | |||
95 | /** |
||
96 | * @param array $availableConfigs |
||
97 | * |
||
98 | * @return Context |
||
99 | */ |
||
100 | public function setAvailableConfigs(array $availableConfigs) |
||
106 | |||
107 | /** |
||
108 | * @param string $configsPath |
||
109 | */ |
||
110 | public function loadConfigsFromPath($configsPath) |
||
121 | |||
122 | /** |
||
123 | * @param mixed $value |
||
124 | * |
||
125 | * @return array |
||
126 | * |
||
127 | * @throws \Exception |
||
128 | */ |
||
129 | public function getConfigurationForValue($value) |
||
143 | |||
144 | /** |
||
145 | * @param mixed $value |
||
146 | * |
||
147 | * @return Meta |
||
148 | */ |
||
149 | public function getMetaForValue($value) |
||
153 | |||
154 | /** |
||
155 | * @param mixed $value |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function isSupported($value) |
||
167 | |||
168 | /** |
||
169 | * @param string $filePath |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function addNewConfig($filePath) |
||
191 | |||
192 | /** |
||
193 | * Set current context page information's. |
||
194 | * |
||
195 | * @param Meta $currentPage |
||
196 | * |
||
197 | * @return self |
||
198 | */ |
||
199 | public function setCurrentPage(Meta $currentPage) |
||
205 | |||
206 | /** |
||
207 | * Get current context page information's. |
||
208 | * |
||
209 | * @return Meta |
||
210 | */ |
||
211 | public function getCurrentPage() |
||
215 | |||
216 | /** |
||
217 | * Register new meta type, registration is required before setting new value for meta. |
||
218 | * |
||
219 | * @param Meta|null $meta Meta object |
||
220 | * |
||
221 | * @throws \Exception if already registered |
||
222 | * |
||
223 | * @return bool if registered successfully |
||
224 | */ |
||
225 | public function registerMeta(Meta $meta = null) |
||
241 | |||
242 | /** |
||
243 | * @return Meta[] |
||
244 | */ |
||
245 | public function getRegisteredMeta() |
||
249 | |||
250 | /** |
||
251 | * {@inheritdoc} |
||
252 | */ |
||
253 | public function offsetSet($name, $meta) |
||
261 | |||
262 | /** |
||
263 | * {@inheritdoc} |
||
264 | */ |
||
265 | public function offsetExists($name) |
||
269 | |||
270 | /** |
||
271 | * {@inheritdoc} |
||
272 | */ |
||
273 | public function offsetUnset($name) |
||
280 | |||
281 | /** |
||
282 | * {@inheritdoc} |
||
283 | */ |
||
284 | public function offsetGet($name) |
||
292 | } |
||
293 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: