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) |
||
166 | |||
167 | /** |
||
168 | * @param array $manager |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | public function getManagerTypes($manager) |
||
178 | |||
179 | /** |
||
180 | * Resolves Elasticsearch type by document class. |
||
181 | * |
||
182 | * @param string $className FQCN or string in AppBundle:Document format |
||
183 | * |
||
184 | * @return string |
||
185 | * @throws \Exception |
||
186 | */ |
||
187 | public function getDocumentType($className) |
||
197 | |||
198 | /** |
||
199 | * Retrieves prepared mapping to sent to the elasticsearch client. |
||
200 | * |
||
201 | * @param array $bundles Manager config. |
||
202 | * |
||
203 | * @return array|null |
||
204 | */ |
||
205 | public function getClientMapping(array $bundles) |
||
229 | |||
230 | /** |
||
231 | * Gathers annotation data from class. |
||
232 | * |
||
233 | * @param \ReflectionClass $reflectionClass Document reflection class to read mapping from. |
||
234 | * |
||
235 | * @return array |
||
236 | */ |
||
237 | private function getDocumentReflectionMapping(\ReflectionClass $reflectionClass) |
||
241 | |||
242 | /** |
||
243 | * Returns single document mapping metadata. |
||
244 | * |
||
245 | * @param string $namespace Document namespace |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | public function getMapping($namespace) |
||
262 | |||
263 | /** |
||
264 | * Adds metadata information to the cache storage. |
||
265 | * |
||
266 | * @param string $bundle |
||
267 | * @param array $mapping |
||
268 | */ |
||
269 | private function cacheBundle($bundle, array $mapping) |
||
276 | |||
277 | /** |
||
278 | * Returns fully qualified class name. |
||
279 | * |
||
280 | * @param string $className |
||
281 | * |
||
282 | * @return string |
||
283 | */ |
||
284 | public function getClassName($className) |
||
288 | } |
||
289 |