1 | <?php |
||
17 | final class RelationDefinition |
||
18 | { |
||
19 | /** |
||
20 | * Relation name. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $name; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $type; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $target; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | private $options = []; |
||
40 | |||
41 | /** |
||
42 | * Name or definition or inversion. |
||
43 | * |
||
44 | * @var string|array |
||
45 | */ |
||
46 | private $inverse = null; |
||
47 | |||
48 | /** |
||
49 | * Defines where relation comes from. |
||
50 | * |
||
51 | * @var RelationContext |
||
52 | */ |
||
53 | private $sourceContext; |
||
54 | |||
55 | /** |
||
56 | * Defines where relation points to (if any). |
||
57 | * |
||
58 | * @var RelationContext|null |
||
59 | */ |
||
60 | private $targetContext; |
||
61 | |||
62 | /** |
||
63 | * @param string $name |
||
64 | * @param string $type |
||
65 | * @param string $target |
||
66 | * @param array $options |
||
67 | * @param string|array $inverse Name or definition of relation to inversed to. |
||
68 | */ |
||
69 | public function __construct( |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getName(): string |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | public function getType(): string |
||
98 | |||
99 | /** |
||
100 | * Target class name, see more information about target context via targetContext() method. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getTarget(): string |
||
108 | |||
109 | /** |
||
110 | * Indicates that relation must be late binded. In relations like that targetContext() can |
||
111 | * return null. |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | public function isLateBinded(): bool |
||
119 | |||
120 | /** |
||
121 | * @return array |
||
122 | */ |
||
123 | public function getOptions(): array |
||
127 | |||
128 | /** |
||
129 | * Source context (where relation comes from). |
||
130 | * |
||
131 | * @return RelationContext |
||
132 | */ |
||
133 | public function sourceContext(): RelationContext |
||
141 | |||
142 | /** |
||
143 | * Target context if any. |
||
144 | * |
||
145 | * @return null|RelationContext |
||
146 | */ |
||
147 | public function targetContext() |
||
151 | |||
152 | /** |
||
153 | * Set relation contexts. |
||
154 | * |
||
155 | * @param RelationContext $source |
||
156 | * @param RelationContext|null $target |
||
157 | * |
||
158 | * @return RelationDefinition |
||
159 | */ |
||
160 | public function withContext(RelationContext $source, RelationContext $target = null): self |
||
168 | |||
169 | /** |
||
170 | * Create version of definition with different set of options. |
||
171 | * |
||
172 | * @param array $options |
||
173 | * |
||
174 | * @return RelationDefinition |
||
175 | */ |
||
176 | public function withOptions(array $options): self |
||
183 | |||
184 | /** |
||
185 | * Checks if inversion if required. |
||
186 | * |
||
187 | * @return bool |
||
188 | */ |
||
189 | public function needInversion(): bool |
||
193 | |||
194 | /** |
||
195 | * Name of relation to be inversed to. |
||
196 | * |
||
197 | * @return string|array |
||
198 | */ |
||
199 | public function getInverse() |
||
207 | } |