1 | <?php |
||
20 | trait ElementByString |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var [ElementInterface[]] |
||
25 | */ |
||
26 | protected $cacheByString = []; |
||
27 | |||
28 | /******************************************* |
||
29 | * ABSTRACTS |
||
30 | *******************************************/ |
||
31 | |||
32 | /** |
||
33 | * @return string |
||
34 | */ |
||
35 | abstract protected function stringProperty(): string; |
||
36 | |||
37 | /** |
||
38 | * @param $string |
||
39 | * @param int|null $siteId |
||
40 | * @return BaseElement|ElementInterface|null |
||
41 | */ |
||
42 | abstract protected function freshFindByString(string $string, int $siteId = null); |
||
43 | |||
44 | /** |
||
45 | * @param ElementInterface $element |
||
46 | * @return string |
||
47 | */ |
||
48 | protected function stringValue(ElementInterface $element) |
||
55 | |||
56 | /** |
||
57 | * @param string $string |
||
58 | * @param int|null $siteId |
||
59 | * @return BaseElement|ElementInterface|null |
||
60 | */ |
||
61 | public function findByString(string $string, int $siteId = null) |
||
78 | |||
79 | /** |
||
80 | * @param string $string |
||
81 | * @param int|null $siteId |
||
82 | * @return BaseElement|ElementInterface |
||
83 | * @throws ElementNotFoundException |
||
84 | */ |
||
85 | public function getByString(string $string, int $siteId = null) |
||
95 | |||
96 | |||
97 | /** |
||
98 | * @param string $string |
||
99 | * @param int|null $siteId |
||
100 | * @return BaseElement|ElementInterface |
||
101 | * @throws ElementNotFoundException |
||
102 | */ |
||
103 | public function freshGetByString(string $string, int $siteId = null) |
||
112 | |||
113 | |||
114 | /******************************************* |
||
115 | * CACHE |
||
116 | *******************************************/ |
||
117 | |||
118 | /** |
||
119 | * Find an existing cache by Handle |
||
120 | * |
||
121 | * @param string $string |
||
122 | * @param int|null $siteId |
||
123 | * @return BaseElement|ElementInterface|null |
||
124 | */ |
||
125 | public function findCacheByString(string $string, int $siteId = null) |
||
135 | |||
136 | /** |
||
137 | * Identify whether in cached by string |
||
138 | * |
||
139 | * @param $string |
||
140 | * @param int|null $siteId |
||
141 | * @return bool |
||
142 | */ |
||
143 | protected function isCachedByString($string, int $siteId = null) |
||
155 | |||
156 | /** |
||
157 | * @param ElementInterface $element |
||
158 | * @return $this |
||
159 | */ |
||
160 | protected function cacheByString(ElementInterface $element) |
||
182 | |||
183 | |||
184 | |||
185 | |||
186 | /******************************************* |
||
187 | * EXCEPTIONS |
||
188 | *******************************************/ |
||
189 | |||
190 | /** |
||
191 | * @param null $string |
||
192 | * @throws ElementNotFoundException |
||
193 | */ |
||
194 | protected function notFoundByStringException($string = null) |
||
204 | } |
||
205 |