1 | <?php |
||
24 | trait ElementAccessorByString |
||
25 | { |
||
26 | use ElementAccessor { |
||
27 | find as parentFind; |
||
28 | findCache as parentFindCache; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @var [ElementInterface[]] |
||
33 | */ |
||
34 | protected $cacheByString = []; |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | abstract protected function stringProperty(): string; |
||
40 | |||
41 | /******************************************* |
||
42 | * STRING |
||
43 | *******************************************/ |
||
44 | |||
45 | /** |
||
46 | * @param ElementInterface $element |
||
47 | * @return string |
||
48 | */ |
||
49 | protected function stringValue(ElementInterface $element) |
||
55 | |||
56 | |||
57 | /******************************************* |
||
58 | * FIND OVERRIDES |
||
59 | *******************************************/ |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function find($identifier, int $siteId = null, string $toScenario = null) |
||
76 | |||
77 | /******************************************* |
||
78 | * CACHE OVERRIDES |
||
79 | *******************************************/ |
||
80 | |||
81 | /** |
||
82 | * @inheritdoc |
||
83 | */ |
||
84 | public function findCache($identifier, int $siteId = null) |
||
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | public function addToCache(ElementInterface $element) |
||
106 | |||
107 | |||
108 | /******************************************* |
||
109 | * FIND/GET BY STRING |
||
110 | *******************************************/ |
||
111 | |||
112 | /** |
||
113 | * @param string $string |
||
114 | * @param int|null $siteId |
||
115 | * @param string|null $toScenario |
||
116 | * @return ElementInterface|null |
||
117 | */ |
||
118 | public function findByString(string $string, int $siteId = null, string $toScenario = null) |
||
133 | |||
134 | /** |
||
135 | * @param string $string |
||
136 | * @param string|null $toScenario |
||
137 | * @return ElementInterface|null |
||
138 | * @throws ElementNotFoundException |
||
139 | */ |
||
140 | public function getByString(string $string, string $toScenario = null): ElementInterface |
||
148 | |||
149 | /** |
||
150 | * @param string $string |
||
151 | * @param int|null $siteId |
||
152 | * @param string $toScenario |
||
153 | * @return ElementInterface|null |
||
154 | */ |
||
155 | public function freshFindByString(string $string, int $siteId = null, string $toScenario = null) |
||
170 | |||
171 | /** |
||
172 | * @param string $string |
||
173 | * @param string|null $toScenario |
||
174 | * @return ElementInterface |
||
175 | * @throws ElementNotFoundException |
||
176 | */ |
||
177 | public function freshGetByString(string $string, string $toScenario = null): ElementInterface |
||
185 | |||
186 | |||
187 | /******************************************* |
||
188 | * CACHE BY STRING |
||
189 | *******************************************/ |
||
190 | |||
191 | /** |
||
192 | * Find an existing cache by ID |
||
193 | * |
||
194 | * @param string $string |
||
195 | * @param int|null $siteId |
||
196 | * @return ElementInterface|null |
||
197 | */ |
||
198 | public function findCacheByString(string $string, int $siteId = null) |
||
208 | |||
209 | /** |
||
210 | * Identify whether in cached by ID |
||
211 | * |
||
212 | * @param string $string |
||
213 | * @param int|null $siteId |
||
214 | * @return bool |
||
215 | */ |
||
216 | protected function isCachedByString(string $string, int $siteId = null): bool |
||
226 | |||
227 | /** |
||
228 | * @param ElementInterface $element |
||
229 | * @return $this |
||
230 | */ |
||
231 | protected function cacheByString(ElementInterface $element) |
||
249 | |||
250 | /******************************************* |
||
251 | * EXCEPTIONS |
||
252 | *******************************************/ |
||
253 | |||
254 | /** |
||
255 | * @param string|null $string |
||
256 | * @throws ElementNotFoundException |
||
257 | */ |
||
258 | protected function notFoundByStringException(string $string = null) |
||
267 | } |
||
268 |