1 | <?php |
||
14 | final class RelationDefinition |
||
15 | { |
||
16 | /** |
||
17 | * Relation name. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | private $name; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $type; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $target; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $options = []; |
||
37 | |||
38 | /** |
||
39 | * Name of relation to be inversed to. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $inverse = null; |
||
44 | |||
45 | /** |
||
46 | * Defines where relation comes from. |
||
47 | * |
||
48 | * @var RelationContext |
||
49 | */ |
||
50 | private $sourceContext; |
||
51 | |||
52 | /** |
||
53 | * Defines where relation points to (if any). |
||
54 | * |
||
55 | * @var RelationContext|null |
||
56 | */ |
||
57 | private $targetContext; |
||
58 | |||
59 | /** |
||
60 | * @param string $name |
||
61 | * @param string $type |
||
62 | * @param string $target |
||
63 | * @param array $options |
||
64 | * @param mixed $inverse Name of relation to inversed to. |
||
65 | */ |
||
66 | public function __construct( |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getName(): string |
||
87 | |||
88 | /** |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getType(): string |
||
95 | |||
96 | /** |
||
97 | * Target class name, see more information about target context via targetContext() method. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getTarget(): string |
||
105 | |||
106 | /** |
||
107 | * @return array |
||
108 | */ |
||
109 | public function getOptions(): array |
||
113 | |||
114 | /** |
||
115 | * Source context (where relation comes from). |
||
116 | * |
||
117 | * @return RelationContext |
||
118 | */ |
||
119 | public function sourceContext(): RelationContext |
||
127 | |||
128 | /** |
||
129 | * Target context if any. |
||
130 | * |
||
131 | * @return null|RelationContext |
||
132 | */ |
||
133 | public function targetContext() |
||
137 | |||
138 | /** |
||
139 | * Set relation contexts. |
||
140 | * |
||
141 | * @param RelationContext $source |
||
142 | * @param RelationContext|null $target |
||
143 | * |
||
144 | * @return RelationDefinition |
||
145 | */ |
||
146 | public function withContext(RelationContext $source, RelationContext $target = null): self |
||
154 | |||
155 | /** |
||
156 | * Create version of definition with different set of options. |
||
157 | * |
||
158 | * @param array $options |
||
159 | * |
||
160 | * @return RelationDefinition |
||
161 | */ |
||
162 | public function withOptions(array $options): self |
||
169 | |||
170 | /** |
||
171 | * Checks if inversion if required. |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function needInversion(): bool |
||
179 | |||
180 | /** |
||
181 | * Name of relation to be inversed to. |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | public function getInverse(): string |
||
189 | } |