1 | <?php |
||
15 | trait RelationshipsContainer |
||
16 | { |
||
17 | /** |
||
18 | * Relationships |
||
19 | * |
||
20 | * @var AbstractRelationship[] |
||
21 | */ |
||
22 | protected $relationships = []; |
||
23 | |||
24 | /** |
||
25 | * Set relationship |
||
26 | * |
||
27 | * @param string $name |
||
28 | * @param AbstractRelationship $relationship |
||
29 | */ |
||
30 | 2 | public function setRelationship(string $name, AbstractRelationship $relationship) |
|
34 | |||
35 | /** |
||
36 | * Has relationship |
||
37 | * |
||
38 | * @param string $name |
||
39 | * @return bool |
||
40 | */ |
||
41 | 1 | public function hasRelationship(string $name): bool |
|
45 | |||
46 | /** |
||
47 | * Get relationship |
||
48 | * |
||
49 | * @param string $name |
||
50 | * @return AbstractRelationship |
||
51 | */ |
||
52 | 1 | public function getRelationship(string $name): AbstractRelationship |
|
56 | |||
57 | /** |
||
58 | * Contains any relationships ? |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function hasRelationships(): bool |
||
63 | { |
||
64 | return count($this->relationships) > 0; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Get relationships |
||
69 | * |
||
70 | * @return AbstractRelationship[] |
||
71 | */ |
||
72 | 1 | public function getRelationships(): array |
|
76 | |||
77 | /** |
||
78 | * Cast relationships to an array |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | 5 | protected function relationshipsToArray(): array |
|
93 | } |