1 | <?php |
||
15 | abstract class AbstractDictionary implements DictionaryInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $name = ''; |
||
21 | |||
22 | /** |
||
23 | * @var DataProviderInterface |
||
24 | */ |
||
25 | protected $dataProvider = null; |
||
26 | |||
27 | /** |
||
28 | * @var callable |
||
29 | */ |
||
30 | protected $view = null; |
||
31 | |||
32 | /** |
||
33 | * @var \Psr\SimpleCache\CacheInterface |
||
34 | */ |
||
35 | protected $cache = null; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $cacheTTL = 0; |
||
41 | |||
42 | /** |
||
43 | * @var iterable |
||
44 | */ |
||
45 | protected $data = []; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $searchFields = []; |
||
51 | |||
52 | /** |
||
53 | * @var bool |
||
54 | */ |
||
55 | protected $dataLoaded = false; |
||
56 | |||
57 | /** |
||
58 | * AbstractDictionary constructor. |
||
59 | * @param string $name |
||
60 | */ |
||
61 | public function __construct(string $name = '') |
||
65 | |||
66 | /** |
||
67 | * @param callable|null $view |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function setDefaultView(callable $view = null) |
||
76 | |||
77 | /** |
||
78 | * @return null|DataProviderInterface |
||
79 | */ |
||
80 | public function getDataProvider(): ?DataProviderInterface |
||
84 | |||
85 | /** |
||
86 | * @param DataProviderInterface $provider |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function setDataProvider(DataProviderInterface $provider) |
||
95 | |||
96 | /** |
||
97 | * @return \Iterator |
||
98 | */ |
||
99 | public function getIterator(): iterable |
||
111 | |||
112 | /** |
||
113 | * @return callable|null |
||
114 | */ |
||
115 | public function getDefaultView(): ?callable |
||
119 | |||
120 | /** |
||
121 | * @return mixed |
||
122 | */ |
||
123 | public function getData(): iterable |
||
148 | |||
149 | /** |
||
150 | * @return CacheInterface |
||
151 | */ |
||
152 | public function getCache(): ?CacheInterface |
||
156 | |||
157 | /** |
||
158 | * @param CacheInterface $cache |
||
159 | * @param int $ttl |
||
160 | * @return $this |
||
161 | */ |
||
162 | public function setCache(CacheInterface $cache, int $ttl = 3600) |
||
169 | |||
170 | /** |
||
171 | * @return iterable |
||
172 | */ |
||
173 | abstract protected function loadData(): iterable; |
||
174 | |||
175 | /** |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getName(): string |
||
182 | |||
183 | /** |
||
184 | * @param string $name |
||
185 | * @return self |
||
186 | */ |
||
187 | public function setName(string $name) |
||
193 | |||
194 | /** |
||
195 | * @param callable $callable |
||
196 | * @return \Generator |
||
197 | */ |
||
198 | public function withView(callable $callable = null): iterable |
||
206 | |||
207 | /** |
||
208 | * @return int |
||
209 | */ |
||
210 | public function count(): int |
||
214 | |||
215 | /** |
||
216 | * @param string $pattern |
||
217 | * @param bool $strict |
||
218 | * @return iterable |
||
219 | */ |
||
220 | public function search(string $pattern, bool $strict = false): iterable |
||
238 | |||
239 | /** |
||
240 | * @param bool $strict |
||
241 | * @return array |
||
242 | */ |
||
243 | public function getSearchFields(bool $strict = false): array |
||
247 | |||
248 | /** |
||
249 | * @param array $searchFields |
||
250 | * @return $this |
||
251 | */ |
||
252 | public function setSearchFields(array $searchFields) |
||
258 | } |
||
259 |