1 | <?php |
||
25 | abstract class Element extends BaseComponent |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * @var [ElementInterface[]] |
||
30 | */ |
||
31 | protected $cacheById = []; |
||
32 | |||
33 | /******************************************* |
||
34 | * ELEMENT CLASSES |
||
35 | *******************************************/ |
||
36 | |||
37 | /** |
||
38 | * @return string |
||
39 | */ |
||
40 | abstract public static function elementClass(): string; |
||
41 | |||
42 | /** |
||
43 | * The element instance that this class interacts with |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | public static function elementClassInstance(): string |
||
51 | |||
52 | /******************************************* |
||
53 | * CREATE |
||
54 | *******************************************/ |
||
55 | |||
56 | /** |
||
57 | * @param array $config |
||
58 | * @return BaseElement|ElementInterface |
||
59 | */ |
||
60 | public function create(array $config = []) |
||
72 | |||
73 | |||
74 | /** |
||
75 | * @param $identifier |
||
76 | * @param int|null $siteId |
||
77 | * @return BaseElement|ElementInterface|null |
||
78 | */ |
||
79 | public function find($identifier, int $siteId = null) |
||
96 | |||
97 | /** |
||
98 | * @param int $id |
||
99 | * @param int|null $siteId |
||
100 | * @return BaseElement|ElementInterface|null |
||
101 | */ |
||
102 | public function findById(int $id, int $siteId = null) |
||
119 | |||
120 | /******************************************* |
||
121 | * GET |
||
122 | *******************************************/ |
||
123 | |||
124 | /** |
||
125 | * @param $identifier |
||
126 | * @param int|null $siteId |
||
127 | * @return BaseElement|ElementInterface |
||
128 | * @throws ElementNotFoundException |
||
129 | */ |
||
130 | public function get($identifier, int $siteId = null) |
||
140 | |||
141 | /** |
||
142 | * @param int $id |
||
143 | * @param int|null $siteId |
||
144 | * @return BaseElement|ElementInterface |
||
145 | * @throws ElementNotFoundException |
||
146 | */ |
||
147 | public function getById(int $id, int $siteId = null) |
||
157 | |||
158 | /******************************************* |
||
159 | * FRESH FIND |
||
160 | *******************************************/ |
||
161 | |||
162 | /** |
||
163 | * @param int $id |
||
164 | * @param int|null $siteId |
||
165 | * @return BaseElement|ElementInterface|null |
||
166 | */ |
||
167 | public function freshFindById(int $id, int $siteId = null) |
||
171 | |||
172 | /** |
||
173 | * @param $id |
||
174 | * @param int|null $siteId |
||
175 | * @return BaseElement|ElementInterface |
||
176 | * @throws ElementNotFoundException |
||
177 | */ |
||
178 | public function freshGetById($id, int $siteId = null) |
||
187 | |||
188 | |||
189 | /******************************************* |
||
190 | * QUERY |
||
191 | *******************************************/ |
||
192 | |||
193 | /** |
||
194 | * Get query |
||
195 | * |
||
196 | * @param $criteria |
||
197 | * @return ElementQueryInterface |
||
198 | */ |
||
199 | public function getQuery($criteria = []) |
||
216 | |||
217 | /******************************************* |
||
218 | * CACHE |
||
219 | *******************************************/ |
||
220 | |||
221 | /** |
||
222 | * @param $identifier |
||
223 | * @param int|null $siteId |
||
224 | * @return BaseElement|ElementInterface|null |
||
225 | */ |
||
226 | public function findCache($identifier, int $siteId = null) |
||
235 | |||
236 | /** |
||
237 | * @param ElementInterface $element |
||
238 | * @return $this |
||
239 | */ |
||
240 | public function addToCache(ElementInterface $element) |
||
247 | |||
248 | /** |
||
249 | * Find an existing cache by ID |
||
250 | * |
||
251 | * @param int $id |
||
252 | * @param int|null $siteId |
||
253 | * @return BaseElement|ElementInterface|null |
||
254 | */ |
||
255 | public function findCacheById(int $id, int $siteId = null) |
||
268 | |||
269 | /** |
||
270 | * Identify whether in cached by ID |
||
271 | * |
||
272 | * @param int $id |
||
273 | * @param int|null $siteId |
||
274 | * @return bool |
||
275 | */ |
||
276 | protected function isCachedById(int $id, int $siteId = null) |
||
287 | |||
288 | /** |
||
289 | * @param ElementInterface $element |
||
290 | * @return $this |
||
291 | */ |
||
292 | protected function cacheById(ElementInterface $element) |
||
309 | |||
310 | /******************************************* |
||
311 | * EXCEPTIONS |
||
312 | *******************************************/ |
||
313 | |||
314 | /** |
||
315 | * @throws ElementNotFoundException |
||
316 | */ |
||
317 | protected function notFoundException() |
||
326 | |||
327 | /** |
||
328 | * @param int|null $id |
||
329 | * @throws ElementNotFoundException |
||
330 | */ |
||
331 | protected function notFoundByIdException(int $id = null) |
||
341 | } |
||
342 |