1 | <?php |
||
13 | class FluentDriver implements MappingDriver |
||
14 | { |
||
15 | /** |
||
16 | * @var MapperSet |
||
17 | */ |
||
18 | protected $mappers; |
||
19 | |||
20 | /** |
||
21 | * @type 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[] $mappings |
||
30 | */ |
||
31 | public function __construct(array $mappings = []) |
||
32 | { |
||
33 | 4 | $this->fluentFactory = function (ClassMetadata $metadata) { |
|
34 | 4 | return new Builder(new ClassMetadataBuilder($metadata)); |
|
35 | }; |
||
36 | |||
37 | 14 | $this->mappers = new MapperSet(); |
|
38 | 14 | $this->addMappings($mappings); |
|
39 | 14 | } |
|
40 | |||
41 | /** |
||
42 | * Loads the metadata for the specified class into the provided container. |
||
43 | * |
||
44 | * @param string $className |
||
45 | * @param ClassMetadata $metadata |
||
46 | */ |
||
47 | 6 | public function loadMetadataForClass($className, ClassMetadata $metadata) |
|
48 | { |
||
49 | 6 | $this->mappers->getMapperFor($className)->map( |
|
50 | 5 | $this->getFluent($metadata) |
|
51 | 5 | ); |
|
52 | 5 | } |
|
53 | |||
54 | /** |
||
55 | * Gets the names of all mapped classes known to this driver. |
||
56 | * |
||
57 | * @throws MappingException |
||
58 | * @return string[] The names of all mapped classes known to this driver. |
||
59 | */ |
||
60 | 2 | public function getAllClassNames() |
|
64 | |||
65 | /** |
||
66 | * Returns whether the class with the specified name should have its metadata loaded. |
||
67 | * This is only the case if it is either mapped as an Entity or a MappedSuperclass. |
||
68 | * |
||
69 | * @param string $className |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | 4 | public function isTransient($className) |
|
74 | { |
||
75 | return |
||
76 | 4 | ! $this->mappers->hasMapperFor($className) || |
|
77 | 4 | $this->mappers->getMapperFor($className)->isTransient(); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param string[] $mappings |
||
82 | */ |
||
83 | 14 | public function addMappings(array $mappings = []) |
|
99 | |||
100 | /** |
||
101 | * @param Mapping $mapping |
||
102 | * |
||
103 | * @throws MappingException |
||
104 | * @return void |
||
105 | */ |
||
106 | 9 | public function addMapping(Mapping $mapping) |
|
110 | |||
111 | /** |
||
112 | * @return MapperSet |
||
113 | */ |
||
114 | 5 | public function getMappers() |
|
118 | |||
119 | /** |
||
120 | * Override the default Fluent factory method with a custom one. |
||
121 | * Use this to implement your own Fluent builder. |
||
122 | * The method will receive a ClassMetadata object as its only argument. |
||
123 | * |
||
124 | * @param callable $factory |
||
125 | */ |
||
126 | 1 | public function setFluentFactory(callable $factory) |
|
130 | |||
131 | /** |
||
132 | * @param ClassMetadata $metadata |
||
133 | * @return Fluent |
||
134 | */ |
||
135 | 5 | protected function getFluent(ClassMetadata $metadata) |
|
139 | } |
||
140 |