1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cycle\Schema\Definition; |
6
|
|
|
|
7
|
|
|
use Cycle\Schema\Definition\Map\OptionMap; |
8
|
|
|
use Cycle\Schema\Exception\RelationException; |
9
|
|
|
|
10
|
|
|
final class Relation |
11
|
|
|
{ |
12
|
|
|
/** @var OptionMap */ |
13
|
|
|
private $options; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
private $type; |
17
|
|
|
|
18
|
|
|
/** @var non-empty-string */ |
|
|
|
|
19
|
|
|
private $target; |
20
|
|
|
|
21
|
|
|
/** @var string|null */ |
22
|
|
|
private $inverse = null; |
23
|
|
|
|
24
|
|
|
/** @var string|null */ |
25
|
|
|
private $inverseType = null; |
26
|
|
|
|
27
|
|
|
/** @var int|null */ |
28
|
|
|
private $inverseLoad = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Relation constructor. |
32
|
|
|
*/ |
33
|
1242 |
|
public function __construct() |
34
|
|
|
{ |
35
|
1242 |
|
$this->options = new OptionMap(); |
36
|
1242 |
|
} |
37
|
|
|
|
38
|
|
|
public function getOptions(): OptionMap |
39
|
|
|
{ |
40
|
|
|
return $this->options; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function setType(string $type): self |
44
|
|
|
{ |
45
|
|
|
$this->type = $type; |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
1192 |
|
|
50
|
|
|
public function getType(): string |
51
|
1192 |
|
{ |
52
|
|
|
if ($this->type === null) { |
53
|
|
|
throw new RelationException('Relation type must be set'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $this->type; |
57
|
|
|
} |
58
|
|
|
|
59
|
1232 |
|
/** |
60
|
|
|
* @param non-empty-string $target |
|
|
|
|
61
|
1232 |
|
* |
62
|
|
|
*/ |
63
|
1232 |
|
public function setTarget(string $target): self |
64
|
|
|
{ |
65
|
|
|
$this->target = $target; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
1170 |
|
|
70
|
|
|
/** |
71
|
1170 |
|
* @return non-empty-string |
|
|
|
|
72
|
2 |
|
*/ |
73
|
|
|
public function getTarget(): string |
74
|
|
|
{ |
75
|
1168 |
|
if ($this->target === null) { |
76
|
|
|
throw new RelationException('Relation target must be set'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $this->target; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setInverse(string $into, string $as, ?int $load = null): self |
83
|
1232 |
|
{ |
84
|
|
|
$this->inverse = $into; |
85
|
1232 |
|
$this->inverseType = $as; |
86
|
|
|
$this->inverseLoad = $load; |
87
|
1232 |
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function isInversed(): bool |
92
|
|
|
{ |
93
|
1194 |
|
return $this->inverse !== null; |
94
|
|
|
} |
95
|
1194 |
|
|
96
|
2 |
|
public function getInverseName(): ?string |
97
|
|
|
{ |
98
|
|
|
return $this->inverse; |
99
|
1192 |
|
} |
100
|
|
|
|
101
|
|
|
public function getInverseType(): ?string |
102
|
|
|
{ |
103
|
|
|
return $this->inverseType; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getInverseLoad(): ?int |
107
|
|
|
{ |
108
|
|
|
return $this->inverseLoad; |
109
|
256 |
|
} |
110
|
|
|
|
111
|
256 |
|
/** |
112
|
256 |
|
* Cloning. |
113
|
256 |
|
*/ |
114
|
|
|
public function __clone() |
115
|
256 |
|
{ |
116
|
|
|
$this->options = clone $this->options; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|