1 | <?php |
||
11 | class Relationship |
||
12 | { |
||
13 | const TYPE_X_TO_ONE = 1; |
||
14 | const TYPE_X_TO_MANY = 2; |
||
15 | |||
16 | /** |
||
17 | * Unique name |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $name; |
||
22 | |||
23 | /** |
||
24 | * Type |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $relationType; |
||
29 | |||
30 | /** |
||
31 | * Collection of links |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $links = []; |
||
36 | |||
37 | /** |
||
38 | * Extra metadata |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $metadata = []; |
||
43 | |||
44 | /** |
||
45 | * Getter-method to access related data |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $getter; |
||
50 | |||
51 | /** |
||
52 | * Getter-method to access an identifier of related object |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $identifierGetter; |
||
57 | |||
58 | /** |
||
59 | * Type of related resource |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $resourceType; |
||
64 | |||
65 | /** |
||
66 | * Relationship constructor. |
||
67 | * |
||
68 | * @param string $name |
||
69 | * @param int $relationType |
||
70 | */ |
||
71 | 2 | public function __construct(string $name, int $relationType) |
|
76 | |||
77 | /** |
||
78 | * Get name |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 2 | public function getName(): string |
|
86 | |||
87 | /** |
||
88 | * Set link |
||
89 | * |
||
90 | * @param string $name |
||
91 | * @param LinkInterface $link |
||
92 | */ |
||
93 | public function setLink(string $name, LinkInterface $link) |
||
101 | |||
102 | /** |
||
103 | * Get links |
||
104 | * [name => link-object] |
||
105 | * |
||
106 | * @return LinkInterface[] |
||
107 | */ |
||
108 | public function getLinks(): array |
||
112 | |||
113 | /** |
||
114 | * Get metadata to include into document's relationship |
||
115 | * [name => value] |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function getMetadata(): array |
||
123 | |||
124 | /** |
||
125 | * Is x-to-many type of relationship ? |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | 2 | public function isCollection(): bool |
|
133 | |||
134 | /** |
||
135 | * Set name of a getter-method to access related data |
||
136 | * |
||
137 | * @param string $method |
||
138 | */ |
||
139 | 2 | public function setGetter(string $method) |
|
143 | |||
144 | /** |
||
145 | * Get name of a getter-method to access related data |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | 2 | public function getGetter(): string |
|
153 | |||
154 | /** |
||
155 | * Set getter-method to access an identifier of related object |
||
156 | * |
||
157 | * @param string $method |
||
158 | */ |
||
159 | 2 | public function setIdentifierGetter(string $method) |
|
163 | |||
164 | /** |
||
165 | * Has identifier type defined ? |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | 2 | public function hasIdentifierGetter(): bool |
|
173 | |||
174 | /** |
||
175 | * Get getter-method to access an identifier of related object |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | 2 | public function getIdentifierGetter(): string |
|
183 | |||
184 | /** |
||
185 | * Set type of resource |
||
186 | * |
||
187 | * @param string $type |
||
188 | */ |
||
189 | 2 | public function setResourceType(string $type) |
|
193 | |||
194 | /** |
||
195 | * Has resource type defined ? |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | 2 | public function hasResourceType(): bool |
|
203 | |||
204 | /** |
||
205 | * Get type of resource |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | 2 | public function getResourceType(): string |
|
213 | } |