1 | <?php |
||
20 | class RelationBuilder |
||
21 | { |
||
22 | /** |
||
23 | * @invisible |
||
24 | * @var RelationsConfig |
||
25 | */ |
||
26 | protected $config; |
||
27 | |||
28 | /** |
||
29 | * @invisible |
||
30 | * @var FactoryInterface |
||
31 | */ |
||
32 | protected $factory; |
||
33 | |||
34 | /** |
||
35 | * Set of relation definitions. |
||
36 | * |
||
37 | * @var RelationInterface[] |
||
38 | */ |
||
39 | private $relations = []; |
||
40 | |||
41 | /** |
||
42 | * @param RelationsConfig $config |
||
43 | * @param FactoryInterface $factory |
||
44 | */ |
||
45 | public function __construct(RelationsConfig $config, FactoryInterface $factory) |
||
50 | |||
51 | /** |
||
52 | * Registering new relation definition. At this moment function would not check if relation is |
||
53 | * unique and will redeclare it. |
||
54 | * |
||
55 | * @param SchemaBuilder $builder |
||
56 | * @param RelationDefinition $definition Relation options (definition). |
||
57 | * |
||
58 | * @throws DefinitionException |
||
59 | */ |
||
60 | public function registerRelation(SchemaBuilder $builder, RelationDefinition $definition) |
||
88 | |||
89 | /** |
||
90 | * Create inverse relations where needed. |
||
91 | * |
||
92 | * @param SchemaBuilder $builder |
||
93 | * |
||
94 | * @throws DefinitionException |
||
95 | */ |
||
96 | public function inverseRelations(SchemaBuilder $builder) |
||
121 | |||
122 | /** |
||
123 | * All declared relations. |
||
124 | * |
||
125 | * @return RelationInterface[] |
||
126 | */ |
||
127 | public function getRelations(): array |
||
131 | |||
132 | /** |
||
133 | * Declare set of tables for each relation. Method must return Generator of AbstractTable |
||
134 | * sequentially (attention, non sequential processing will cause collision issues between |
||
135 | * tables). |
||
136 | * |
||
137 | * @param SchemaBuilder $builder |
||
138 | * |
||
139 | * @return \Generator |
||
140 | */ |
||
141 | public function declareTables(SchemaBuilder $builder): \Generator |
||
149 | |||
150 | /** |
||
151 | * Pack relation schemas for specific model class in order to be saved in memory. |
||
152 | * |
||
153 | * @param string $class |
||
154 | * @param SchemaBuilder $builder |
||
155 | * |
||
156 | * @return array |
||
157 | */ |
||
158 | public function packRelations(string $class, SchemaBuilder $builder): array |
||
172 | |||
173 | /** |
||
174 | * Populate entity target based on interface or role. |
||
175 | * |
||
176 | * @param SchemaBuilder $builder |
||
177 | * @param \Spiral\ORM\Schemas\Definitions\RelationDefinition $definition |
||
178 | * |
||
179 | * @return \Spiral\ORM\Schemas\Definitions\RelationDefinition |
||
180 | * |
||
181 | * @throws DefinitionException |
||
182 | */ |
||
183 | protected function locateOuter( |
||
226 | |||
227 | /** |
||
228 | * Check if schema matches relation target. |
||
229 | * |
||
230 | * @param string $target |
||
231 | * @param \Spiral\ORM\Schemas\SchemaInterface $schema |
||
232 | * |
||
233 | * @return bool |
||
234 | */ |
||
235 | private function matchBinded(string $target, SchemaInterface $schema): bool |
||
248 | } |