1 | <?php |
||
12 | class ClassMapDriver implements MappingDriver |
||
13 | { |
||
14 | /** |
||
15 | * @var array|string[] |
||
16 | */ |
||
17 | private $classMap; |
||
18 | |||
19 | /** |
||
20 | * @param array|string[] $classMap |
||
21 | */ |
||
22 | 6 | public function __construct(array $classMap) |
|
26 | |||
27 | /** |
||
28 | * @param string $className |
||
29 | * @param ClassMetadataInterface $metadata |
||
30 | * |
||
31 | * @throws MappingException |
||
32 | */ |
||
33 | 4 | public function loadMetadataForClass($className, ClassMetadataInterface $metadata) |
|
34 | { |
||
35 | 4 | if (false === $metadata instanceof ClassMetadata) { |
|
36 | 1 | throw new MappingException( |
|
37 | 1 | sprintf('Metadata is of class "%s" instead of "%s"', get_class($metadata), ClassMetadata::class) |
|
38 | ); |
||
39 | } |
||
40 | |||
41 | 3 | if (false === isset($this->classMap[$className])) { |
|
42 | 1 | throw new MappingException( |
|
43 | 1 | sprintf('No configured mapping for document "%s"', $className) |
|
44 | ); |
||
45 | } |
||
46 | |||
47 | 2 | $mappingClassName = $this->classMap[$className]; |
|
48 | |||
49 | 2 | if (false === ($mapping = new $mappingClassName()) instanceof ClassMapMappingInterface) { |
|
50 | 1 | throw new MappingException( |
|
51 | 1 | sprintf('Class "%s" does not implement the "%s"', $mappingClassName, ClassMapMappingInterface::class) |
|
52 | ); |
||
53 | } |
||
54 | |||
55 | 1 | $mapping->configureMapping($metadata); |
|
56 | 1 | } |
|
57 | |||
58 | /** |
||
59 | * @return array |
||
60 | */ |
||
61 | 1 | public function getAllClassNames(): array |
|
65 | |||
66 | /** |
||
67 | * @param string $className |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 1 | public function isTransient($className): bool |
|
79 | } |
||
80 |