1 | <?php |
||
19 | class MetadataCollector |
||
20 | { |
||
21 | /** |
||
22 | * @var DocumentFinder |
||
23 | */ |
||
24 | private $finder; |
||
25 | |||
26 | /** |
||
27 | * @var DocumentParser |
||
28 | */ |
||
29 | private $parser; |
||
30 | |||
31 | /** |
||
32 | * @var CacheProvider |
||
33 | */ |
||
34 | private $cache = null; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $enableCache = false; |
||
40 | |||
41 | /** |
||
42 | * Bundles mappings local cache container. Could be stored as the whole bundle or as single document. |
||
43 | * e.g. AcmeDemoBundle, AcmeDemoBundle:Product. |
||
44 | * |
||
45 | * @var mixed |
||
46 | */ |
||
47 | private $mappings = []; |
||
48 | |||
49 | /** |
||
50 | * @param DocumentFinder $finder For finding documents. |
||
51 | * @param DocumentParser $parser For reading document annotations. |
||
52 | * @param CacheProvider $cache Cache provider to store the meta data for later use. |
||
53 | */ |
||
54 | public function __construct($finder, $parser, $cache = null) |
||
64 | |||
65 | /** |
||
66 | * Enables metadata caching. |
||
67 | * |
||
68 | * @param bool $enableCache |
||
69 | */ |
||
70 | public function setEnableCache($enableCache) |
||
74 | |||
75 | /** |
||
76 | * Fetches bundles mapping from documents. |
||
77 | * |
||
78 | * @param string[] $bundles Elasticsearch manager config. You can get bundles list from 'mappings' node. |
||
79 | * @return array |
||
80 | */ |
||
81 | public function getMappings(array $bundles) |
||
101 | |||
102 | /** |
||
103 | * Searches for documents in the bundle and tries to read them. |
||
104 | * |
||
105 | * @param string $name |
||
106 | * |
||
107 | * @return array Empty array on containing zero documents. |
||
108 | */ |
||
109 | public function getBundleMapping($name) |
||
176 | |||
177 | /** |
||
178 | * @param array $manager |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | public function getManagerTypes($manager) |
||
188 | |||
189 | /** |
||
190 | * Resolves Elasticsearch type by document class. |
||
191 | * |
||
192 | * @param string $className FQCN or string in AppBundle:Document format |
||
193 | * |
||
194 | * @return string |
||
195 | * @throws \Exception |
||
196 | */ |
||
197 | public function getDocumentType($className) |
||
207 | |||
208 | /** |
||
209 | * Retrieves prepared mapping to sent to the elasticsearch client. |
||
210 | * |
||
211 | * @param array $bundles Manager config. |
||
212 | * |
||
213 | * @return array|null |
||
214 | */ |
||
215 | public function getClientMapping(array $bundles) |
||
239 | |||
240 | /** |
||
241 | * Gathers annotation data from class. |
||
242 | * |
||
243 | * @param \ReflectionClass $reflectionClass Document reflection class to read mapping from. |
||
244 | * |
||
245 | * @return array |
||
246 | */ |
||
247 | private function getDocumentReflectionMapping(\ReflectionClass $reflectionClass) |
||
251 | |||
252 | /** |
||
253 | * Returns single document mapping metadata. |
||
254 | * |
||
255 | * @param string $namespace Document namespace |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | public function getMapping($namespace) |
||
272 | |||
273 | /** |
||
274 | * Adds metadata information to the cache storage. |
||
275 | * |
||
276 | * @param string $bundle |
||
277 | * @param array $mapping |
||
278 | */ |
||
279 | private function cacheBundle($bundle, array $mapping) |
||
286 | |||
287 | /** |
||
288 | * Returns fully qualified class name. |
||
289 | * |
||
290 | * @param string $className |
||
291 | * |
||
292 | * @return string |
||
293 | */ |
||
294 | public function getClassName($className) |
||
298 | } |
||
299 |