1 | <?php |
||
11 | class Relationship |
||
12 | { |
||
13 | const TYPE_X_TO_ONE = 1; |
||
14 | const TYPE_X_TO_MANY = 2; |
||
15 | |||
16 | /** |
||
17 | * Name of resource inside of relationships-object |
||
18 | * |
||
19 | * { |
||
20 | * "author": { <--- Name of relationship |
||
21 | * "data": { |
||
22 | * "id": "12345", |
||
23 | * "type": "Author" |
||
24 | * } |
||
25 | * } |
||
26 | * } |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $name; |
||
31 | |||
32 | /** |
||
33 | * Type or relationship: "x to one" or "x to many". |
||
34 | * |
||
35 | * @see for TYPE_* constants. |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $type; |
||
40 | |||
41 | /** |
||
42 | * Collection of links |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $links = []; |
||
47 | |||
48 | /** |
||
49 | * Extra metadata |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $metadata = []; |
||
54 | |||
55 | /** |
||
56 | * Name of property contains related object. |
||
57 | * Value is optional. Can be set only for real properties. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $propertyName; |
||
62 | |||
63 | /** |
||
64 | * Getter-method to access related data |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $getter; |
||
69 | |||
70 | /** |
||
71 | * Getter-method to access an identifier of related object |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | protected $identifierGetter; |
||
76 | |||
77 | /** |
||
78 | * Type of related resource |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | protected $resourceType; |
||
83 | |||
84 | /** |
||
85 | * Relationship constructor. |
||
86 | * |
||
87 | * @param string $name |
||
88 | * @param int $type |
||
89 | */ |
||
90 | 2 | public function __construct(string $name, int $type) |
|
95 | |||
96 | /** |
||
97 | * Get name |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 2 | public function getName(): string |
|
105 | |||
106 | /** |
||
107 | * Set link |
||
108 | * |
||
109 | * @param string $name |
||
110 | * @param LinkInterface $link |
||
111 | */ |
||
112 | public function setLink(string $name, LinkInterface $link) |
||
120 | |||
121 | /** |
||
122 | * Get links |
||
123 | * [name => link-object] |
||
124 | * |
||
125 | * @return LinkInterface[] |
||
126 | */ |
||
127 | public function getLinks(): array |
||
131 | |||
132 | /** |
||
133 | * Get metadata to include into document's relationship |
||
134 | * [name => value] |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getMetadata(): array |
||
142 | |||
143 | /** |
||
144 | * Is x-to-many type of relationship ? |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | 2 | public function isCollection(): bool |
|
152 | |||
153 | /** |
||
154 | * Set name of property contains related object |
||
155 | * |
||
156 | * @param string $name |
||
157 | */ |
||
158 | 2 | public function setPropertyName(string $name) |
|
162 | |||
163 | /** |
||
164 | * Has name of property ? |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function hasPropertyName(): bool |
||
172 | |||
173 | /** |
||
174 | * Get name of property contains related object |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | 1 | public function getPropertyName(): string |
|
182 | |||
183 | /** |
||
184 | * Set name of a getter-method to access related data |
||
185 | * |
||
186 | * @param string $method |
||
187 | */ |
||
188 | 2 | public function setGetter(string $method) |
|
192 | |||
193 | /** |
||
194 | * Get name of a getter-method to access related data |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | 2 | public function getGetter(): string |
|
202 | |||
203 | /** |
||
204 | * Set getter-method to access an identifier of related object |
||
205 | * |
||
206 | * @param string $method |
||
207 | */ |
||
208 | 2 | public function setIdentifierGetter(string $method) |
|
212 | |||
213 | /** |
||
214 | * Has identifier type defined ? |
||
215 | * |
||
216 | * @return bool |
||
217 | */ |
||
218 | 2 | public function hasIdentifierGetter(): bool |
|
222 | |||
223 | /** |
||
224 | * Get getter-method to access an identifier of related object |
||
225 | * |
||
226 | * @return string |
||
227 | */ |
||
228 | 2 | public function getIdentifierGetter(): string |
|
232 | |||
233 | /** |
||
234 | * Set type of resource |
||
235 | * |
||
236 | * @param string $type |
||
237 | */ |
||
238 | 2 | public function setResourceType(string $type) |
|
242 | |||
243 | /** |
||
244 | * Has resource type defined ? |
||
245 | * |
||
246 | * @return bool |
||
247 | */ |
||
248 | 2 | public function hasResourceType(): bool |
|
252 | |||
253 | /** |
||
254 | * Get type of resource |
||
255 | * |
||
256 | * @return string |
||
257 | */ |
||
258 | 2 | public function getResourceType(): string |
|
262 | } |