1 | <?php |
||
13 | class FluentDriver implements MappingDriver |
||
14 | { |
||
15 | /** |
||
16 | * @var MapperSet |
||
17 | */ |
||
18 | protected $mappers; |
||
19 | |||
20 | /** |
||
21 | * @var callable |
||
22 | */ |
||
23 | protected $fluentFactory; |
||
24 | |||
25 | /** |
||
26 | * Initializes a new FileDriver that looks in the given path(s) for mapping |
||
27 | * documents and operates in the specified operating mode. |
||
28 | * |
||
29 | * @param string[]|null $mappings |
||
30 | * @param string[]|null $paths |
||
31 | * |
||
32 | * @throws \Doctrine\ORM\Mapping\MappingException |
||
33 | */ |
||
34 | public function __construct($mappings = null, $paths = null) |
||
35 | { |
||
36 | 4 | $this->fluentFactory = function (ClassMetadata $metadata) { |
|
37 | 4 | return new Builder(new ClassMetadataBuilder($metadata)); |
|
38 | }; |
||
39 | |||
40 | 92 | $this->mappers = new MapperSet(); |
|
41 | |||
42 | 92 | if ($mappings !== null) { |
|
43 | 79 | $this->addMappings($mappings); |
|
44 | 79 | } |
|
45 | |||
46 | 92 | if ($paths !== null) { |
|
47 | $this->addPaths($paths); |
||
48 | } |
||
49 | 92 | } |
|
50 | |||
51 | /** |
||
52 | * Loads the metadata for the specified class into the provided container. |
||
53 | * |
||
54 | * @param string $className |
||
55 | * @param ClassMetadata $metadata |
||
56 | */ |
||
57 | 6 | public function loadMetadataForClass($className, ClassMetadata $metadata) |
|
58 | { |
||
59 | 6 | $this->mappers->getMapperFor($className)->map( |
|
60 | 5 | $this->getFluent($metadata) |
|
61 | 5 | ); |
|
62 | 5 | } |
|
63 | |||
64 | /** |
||
65 | * Gets the names of all mapped classes known to this driver. |
||
66 | * |
||
67 | * @throws MappingException |
||
68 | * |
||
69 | * @return string[] The names of all mapped classes known to this driver. |
||
70 | */ |
||
71 | 12 | public function getAllClassNames() |
|
72 | { |
||
73 | 12 | return $this->mappers->getClassNames(); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * Returns whether the class with the specified name should have its metadata loaded. |
||
78 | * This is only the case if it is either mapped as an Entity or a MappedSuperclass. |
||
79 | * |
||
80 | * @param string $className |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | 4 | public function isTransient($className) |
|
90 | |||
91 | /** |
||
92 | * @param string[] $mappings |
||
93 | */ |
||
94 | 82 | public function addMappings(array $mappings = []) |
|
110 | |||
111 | /** |
||
112 | * @param Mapping $mapping |
||
113 | * |
||
114 | * @throws MappingException |
||
115 | */ |
||
116 | 87 | public function addMapping(Mapping $mapping) |
|
120 | |||
121 | /** |
||
122 | * @return MapperSet |
||
123 | */ |
||
124 | 5 | public function getMappers() |
|
128 | |||
129 | /** |
||
130 | * Add mappings from an array of folders. |
||
131 | * |
||
132 | * @param string[] $paths |
||
133 | * |
||
134 | * @throws MappingException |
||
135 | */ |
||
136 | public function addPaths($paths) |
||
167 | |||
168 | /** |
||
169 | * Override the default Fluent factory method with a custom one. |
||
170 | * Use this to implement your own Fluent builder. |
||
171 | * The method will receive a ClassMetadata object as its only argument. |
||
172 | * |
||
173 | * @param callable $factory |
||
174 | */ |
||
175 | 1 | public function setFluentFactory(callable $factory) |
|
179 | |||
180 | /** |
||
181 | * @param ClassMetadata $metadata |
||
182 | * |
||
183 | * @return Fluent |
||
184 | */ |
||
185 | 5 | protected function getFluent(ClassMetadata $metadata) |
|
189 | } |
||
190 |