1 | <?php |
||
20 | class MetadataCollector |
||
21 | { |
||
22 | /** |
||
23 | * @var DocumentFinder |
||
24 | */ |
||
25 | private $finder; |
||
26 | |||
27 | /** |
||
28 | * @var DocumentParser |
||
29 | */ |
||
30 | private $parser; |
||
31 | |||
32 | /** |
||
33 | * @var CacheProvider |
||
34 | */ |
||
35 | private $cache = null; |
||
36 | |||
37 | /** |
||
38 | * @var bool |
||
39 | */ |
||
40 | private $enableCache = false; |
||
41 | |||
42 | /** |
||
43 | * Bundles mappings local cache container. Could be stored as the whole bundle or as single document. |
||
44 | * e.g. AcmeDemoBundle, AcmeDemoBundle:Product. |
||
45 | * |
||
46 | * @var mixed |
||
47 | */ |
||
48 | private $mappings = []; |
||
49 | |||
50 | /** |
||
51 | * @param DocumentFinder $finder For finding documents. |
||
52 | * @param DocumentParser $parser For reading document annotations. |
||
53 | * @param CacheProvider $cache Cache provider to store the meta data for later use. |
||
54 | */ |
||
55 | public function __construct($finder, $parser, $cache = null) |
||
56 | { |
||
57 | $this->finder = $finder; |
||
58 | $this->parser = $parser; |
||
59 | $this->cache = $cache; |
||
60 | |||
61 | if ($this->cache) { |
||
62 | $this->mappings = $this->cache->fetch('ongr.metadata.mappings'); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Enables metadata caching. |
||
68 | * |
||
69 | * @param bool $enableCache |
||
70 | */ |
||
71 | public function setEnableCache($enableCache) |
||
75 | |||
76 | /** |
||
77 | * Fetches bundles mapping from documents. |
||
78 | * |
||
79 | * @param string[] $bundles Elasticsearch manager config. You can get bundles list from 'mappings' node. |
||
80 | * @return array |
||
81 | */ |
||
82 | public function getMappings(array $bundles) |
||
102 | |||
103 | /** |
||
104 | * Searches for documents in the bundle and tries to read them. |
||
105 | * |
||
106 | * @param string $name |
||
107 | * |
||
108 | * @return array Empty array on containing zero documents. |
||
109 | */ |
||
110 | public function getBundleMapping($name) |
||
178 | |||
179 | /** |
||
180 | * @param array $manager |
||
181 | * |
||
182 | * @return array |
||
183 | */ |
||
184 | public function getManagerTypes($manager) |
||
190 | |||
191 | /** |
||
192 | * Resolves document elasticsearch type, use format: SomeBarBundle:AcmeDocument. |
||
193 | * |
||
194 | * @param string $document |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getDocumentType($document) |
||
204 | |||
205 | /** |
||
206 | * Retrieves document mapping by namespace. |
||
207 | * |
||
208 | * @param string $namespace Document namespace. |
||
209 | * |
||
210 | * @return array|null |
||
211 | */ |
||
212 | public function getMappingByNamespace($namespace) |
||
223 | |||
224 | /** |
||
225 | * Retrieves prepared mapping to sent to the elasticsearch client. |
||
226 | * |
||
227 | * @param array $bundles Manager config. |
||
228 | * |
||
229 | * @return array |
||
230 | */ |
||
231 | public function getClientMapping(array $bundles) |
||
255 | |||
256 | /** |
||
257 | * Gathers annotation data from class. |
||
258 | * |
||
259 | * @param \ReflectionClass $reflectionClass Document reflection class to read mapping from. |
||
260 | * |
||
261 | * @return array |
||
262 | */ |
||
263 | private function getDocumentReflectionMapping(\ReflectionClass $reflectionClass) |
||
267 | |||
268 | /** |
||
269 | * Retrieves mapping from document. |
||
270 | * |
||
271 | * @param DocumentInterface $document |
||
272 | * |
||
273 | * @return array |
||
274 | */ |
||
275 | public function getDocumentMapping(DocumentInterface $document) |
||
279 | |||
280 | /** |
||
281 | * Returns mapping with metadata. |
||
282 | * |
||
283 | * @param string $namespace Bundle or document namespace. |
||
284 | * |
||
285 | * @return array |
||
286 | */ |
||
287 | public function getMapping($namespace) |
||
296 | |||
297 | /** |
||
298 | * Adds metadata information to the cache storage. |
||
299 | * |
||
300 | * @param string $bundle |
||
301 | * @param array $mapping |
||
302 | */ |
||
303 | private function cacheBundle($bundle, array $mapping) |
||
310 | |||
311 | /** |
||
312 | * returns the namespace declared at the start of a file |
||
313 | * @param $filepath |
||
314 | * @return bool |
||
315 | */ |
||
316 | private function getFileNamespace($filepath) |
||
325 | } |
||
326 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: