1 | <?php |
||
16 | class SchemaBuilder |
||
17 | { |
||
18 | /** |
||
19 | * @var MongoManager |
||
20 | */ |
||
21 | private $manager; |
||
22 | |||
23 | /** |
||
24 | * @var SchemaInterface[] |
||
25 | */ |
||
26 | private $schemas = []; |
||
27 | |||
28 | /** |
||
29 | * Class names of sources associated with specific class. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private $sources = []; |
||
34 | |||
35 | /** |
||
36 | * @param MongoManager $manager |
||
37 | */ |
||
38 | public function __construct(MongoManager $manager) |
||
42 | |||
43 | /** |
||
44 | * Add new model schema into pool. |
||
45 | * |
||
46 | * @param SchemaInterface $schema |
||
47 | * |
||
48 | * @return self|$this |
||
49 | */ |
||
50 | public function addSchema(SchemaInterface $schema): SchemaBuilder |
||
56 | |||
57 | /** |
||
58 | * @param string $class |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function hasSchema(string $class): bool |
||
66 | |||
67 | /** |
||
68 | * @param string $class |
||
69 | * |
||
70 | * @return SchemaInterface |
||
71 | * |
||
72 | * @throws SchemaException |
||
73 | */ |
||
74 | public function getSchema(string $class): SchemaInterface |
||
82 | |||
83 | /** |
||
84 | * All available document schemas. |
||
85 | * |
||
86 | * @return SchemaInterface[] |
||
87 | */ |
||
88 | public function getSchemas(): array |
||
92 | |||
93 | /** |
||
94 | * Associate source class with entity class. Source will be automatically associated with given |
||
95 | * class and all classes from the same collection which extends it. |
||
96 | * |
||
97 | * @param string $class |
||
98 | * @param string $source |
||
99 | * |
||
100 | * @return SchemaBuilder |
||
101 | * |
||
102 | * @throws SchemaException |
||
103 | */ |
||
104 | public function addSource(string $class, string $source): SchemaBuilder |
||
133 | |||
134 | /** |
||
135 | * Check if given entity has associated source. |
||
136 | * |
||
137 | * @param string $class |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function hasSource(string $class): bool |
||
145 | |||
146 | /** |
||
147 | * Get source associated with specific class, if any. |
||
148 | * |
||
149 | * @param string $class |
||
150 | * |
||
151 | * @return string|null |
||
152 | */ |
||
153 | public function getSource(string $class) |
||
161 | |||
162 | /** |
||
163 | * Pack declared schemas in a normalized form. |
||
164 | * |
||
165 | * @return array |
||
166 | */ |
||
167 | public function packSchema(): array |
||
193 | |||
194 | /** |
||
195 | * Create all declared indexes. |
||
196 | * |
||
197 | * @throws UnsupportedException |
||
198 | * @throws DriverException |
||
199 | */ |
||
200 | public function createIndexes() |
||
219 | } |