1 | <?php |
||
19 | class RelationBuilder |
||
20 | { |
||
21 | /** |
||
22 | * @invisible |
||
23 | * @var RelationsConfig |
||
24 | */ |
||
25 | protected $config; |
||
26 | |||
27 | /** |
||
28 | * @invisible |
||
29 | * @var FactoryInterface |
||
30 | */ |
||
31 | protected $factory; |
||
32 | |||
33 | /** |
||
34 | * Set of relation definitions. |
||
35 | * |
||
36 | * @var RelationInterface[] |
||
37 | */ |
||
38 | private $relations = []; |
||
39 | |||
40 | /** |
||
41 | * @param RelationsConfig $config |
||
42 | * @param FactoryInterface $factory |
||
43 | */ |
||
44 | public function __construct(RelationsConfig $config, FactoryInterface $factory) |
||
49 | |||
50 | /** |
||
51 | * Registering new relation definition. At this moment function would not check if relation is |
||
52 | * unique and will redeclare it. |
||
53 | * |
||
54 | * @param RelationDefinition $definition Relation options (definition). |
||
55 | * |
||
56 | * @throws DefinitionException |
||
57 | */ |
||
58 | public function registerRelation(RelationDefinition $definition) |
||
79 | |||
80 | /** |
||
81 | * Create inverse relations where needed. |
||
82 | * |
||
83 | * @param SchemaBuilder $builder |
||
84 | * |
||
85 | * @throws DefinitionException |
||
86 | */ |
||
87 | public function inverseRelations(SchemaBuilder $builder) |
||
119 | |||
120 | /** |
||
121 | * All declared relations. |
||
122 | * |
||
123 | * @return RelationInterface[] |
||
124 | */ |
||
125 | public function getRelations(): array |
||
129 | |||
130 | /** |
||
131 | * Declare set of tables for each relation. Method must return Generator of AbstractTable |
||
132 | * sequentially (attention, non sequential processing will cause collision issues between |
||
133 | * tables). |
||
134 | * |
||
135 | * @param SchemaBuilder $builder |
||
136 | * |
||
137 | * @return \Generator |
||
138 | */ |
||
139 | public function declareTables(SchemaBuilder $builder): \Generator |
||
147 | |||
148 | /** |
||
149 | * Pack relation schemas for specific model class in order to be saved in memory. |
||
150 | * |
||
151 | * @param string $class |
||
152 | * @param SchemaBuilder $builder |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | public function packRelations(string $class, SchemaBuilder $builder): array |
||
170 | } |