1 | <?php |
||
19 | class FluentDriver implements MappingDriver |
||
20 | { |
||
21 | /** |
||
22 | * @var MapperSet |
||
23 | */ |
||
24 | protected $mappers; |
||
25 | |||
26 | /** |
||
27 | * @var callable |
||
28 | */ |
||
29 | protected $fluentFactory; |
||
30 | |||
31 | /** |
||
32 | * The file extension of mapping documents. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $fileExtension = '.php'; |
||
37 | |||
38 | /** |
||
39 | * Initializes a new FileDriver that looks in the given path(s) for mapping |
||
40 | * documents and operates in the specified operating mode. |
||
41 | * |
||
42 | * @param string[] $mappings |
||
43 | * @param array $paths |
||
44 | * |
||
45 | * @throws MappingException |
||
46 | */ |
||
47 | public function __construct(array $mappings = [], array $paths = []) |
||
48 | { |
||
49 | 20 | $this->fluentFactory = function (ClassMetadata $metadata) { |
|
50 | 20 | return new Builder(new ClassMetadataBuilder($metadata)); |
|
51 | }; |
||
52 | |||
53 | 380 | $this->mappers = new MapperSet(); |
|
54 | |||
55 | 380 | if (!empty($paths)) { |
|
56 | 4 | $this->loadPaths($paths); |
|
57 | 1 | } |
|
58 | |||
59 | 380 | if (!empty($mappings)) { |
|
60 | 316 | $this->addMappings($mappings); |
|
61 | 79 | } |
|
62 | 380 | } |
|
63 | |||
64 | /** |
||
65 | * Loads the metadata for the specified class into the provided container. |
||
66 | * |
||
67 | * @param string $className |
||
68 | * @param ClassMetadata $metadata |
||
69 | */ |
||
70 | 28 | public function loadMetadataForClass($className, ClassMetadata $metadata) |
|
76 | |||
77 | /** |
||
78 | * Gets the names of all mapped classes known to this driver. |
||
79 | * |
||
80 | * @throws MappingException |
||
81 | * |
||
82 | * @return string[] The names of all mapped classes known to this driver. |
||
83 | */ |
||
84 | 56 | public function getAllClassNames() |
|
88 | |||
89 | /** |
||
90 | * Returns whether the class with the specified name should have its metadata loaded. |
||
91 | * This is only the case if it is either mapped as an Entity or a MappedSuperclass. |
||
92 | * |
||
93 | * @param string $className |
||
94 | * |
||
95 | * @return bool |
||
96 | */ |
||
97 | 24 | public function isTransient($className) |
|
103 | |||
104 | /** |
||
105 | * @param array $paths |
||
106 | * |
||
107 | * @throws MappingException |
||
108 | */ |
||
109 | 12 | public function loadPaths(array $paths) |
|
167 | |||
168 | /** |
||
169 | * @param string[] $mappings |
||
170 | * |
||
171 | * @throws InvalidArgumentException |
||
172 | */ |
||
173 | 328 | public function addMappings(array $mappings = []) |
|
189 | |||
190 | /** |
||
191 | * @param Mapping $mapping |
||
192 | * |
||
193 | * @throws MappingException |
||
194 | * |
||
195 | * @return void |
||
196 | */ |
||
197 | 356 | public function addMapping(Mapping $mapping) |
|
201 | |||
202 | /** |
||
203 | * @return MapperSet |
||
204 | */ |
||
205 | 24 | public function getMappers() |
|
209 | |||
210 | /** |
||
211 | * Override the default Fluent factory method with a custom one. |
||
212 | * Use this to implement your own Fluent builder. |
||
213 | * The method will receive a ClassMetadata object as its only argument. |
||
214 | * |
||
215 | * @param callable $factory |
||
216 | */ |
||
217 | 4 | public function setFluentFactory(callable $factory) |
|
221 | |||
222 | /** |
||
223 | * @param ClassMetadata $metadata |
||
224 | * |
||
225 | * @return Fluent |
||
226 | */ |
||
227 | 24 | protected function getFluent(ClassMetadata $metadata) |
|
231 | } |
||
232 |