1 | <?php |
||
15 | class Relationship implements LinksAwareInterface |
||
16 | { |
||
17 | use LinksContainer; |
||
18 | |||
19 | const TYPE_X_TO_ONE = 1; |
||
20 | const TYPE_X_TO_MANY = 2; |
||
21 | |||
22 | /** |
||
23 | * Name unique name of resource-object inside of relationships-object |
||
24 | * |
||
25 | * { |
||
26 | * "author": { <--- Name of resource-object |
||
27 | * "data": { |
||
28 | * "id": "12345", |
||
29 | * "type": "Author" |
||
30 | * } |
||
31 | * } |
||
32 | * } |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $name; |
||
37 | |||
38 | /** |
||
39 | * Type or relationship: "x to one" or "x to many". |
||
40 | * |
||
41 | * @see for TYPE_* constants. |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $type; |
||
46 | |||
47 | /** |
||
48 | * Extra metadata |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $metadata = []; |
||
53 | |||
54 | /** |
||
55 | * Name of property contains related object. |
||
56 | * Value is optional. Can be set only for real properties. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $propertyName; |
||
61 | |||
62 | /** |
||
63 | * Getter-method to access related data |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $getter; |
||
68 | |||
69 | /** |
||
70 | * Getter-method to access an identifier of related object |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $identifierGetter; |
||
75 | |||
76 | /** |
||
77 | * Type of related resource |
||
78 | * |
||
79 | * @var string |
||
80 | */ |
||
81 | protected $resourceType; |
||
82 | |||
83 | /** |
||
84 | * Relationship constructor. |
||
85 | * |
||
86 | * @param string $name |
||
87 | * @param int $type |
||
88 | */ |
||
89 | 6 | public function __construct(string $name, int $type) |
|
94 | |||
95 | /** |
||
96 | * Get name |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | 6 | public function getName(): string |
|
104 | |||
105 | /** |
||
106 | * Get metadata to include into document's relationship |
||
107 | * [name => value] |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | public function getMetadata(): array |
||
115 | |||
116 | /** |
||
117 | * Is x-to-many type of relationship ? |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | 3 | public function isCollection(): bool |
|
125 | |||
126 | /** |
||
127 | * Set name of property contains related object |
||
128 | * |
||
129 | * @param string $name |
||
130 | */ |
||
131 | 5 | public function setPropertyName(string $name) |
|
135 | |||
136 | /** |
||
137 | * Has name of property ? |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function hasPropertyName(): bool |
||
145 | |||
146 | /** |
||
147 | * Get name of property contains related object |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | 4 | public function getPropertyName(): string |
|
155 | |||
156 | /** |
||
157 | * Set name of a getter-method to access related data |
||
158 | * |
||
159 | * @param string $method |
||
160 | */ |
||
161 | 5 | public function setGetter(string $method) |
|
165 | |||
166 | /** |
||
167 | * Contains name of a getter-method to access related data ? |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function hasGetter(): bool |
||
175 | |||
176 | /** |
||
177 | * Get name of a getter-method to access related data |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | 2 | public function getGetter(): string |
|
185 | |||
186 | /** |
||
187 | * Set getter-method to access an identifier of related object |
||
188 | * |
||
189 | * @param string $method |
||
190 | */ |
||
191 | 4 | public function setIdentifierGetter(string $method) |
|
195 | |||
196 | /** |
||
197 | * Has identifier type defined ? |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | 2 | public function hasIdentifierGetter(): bool |
|
205 | |||
206 | /** |
||
207 | * Get getter-method to access an identifier of related object |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | 2 | public function getIdentifierGetter(): string |
|
215 | |||
216 | /** |
||
217 | * Set type of resource |
||
218 | * |
||
219 | * @param string $type |
||
220 | */ |
||
221 | 4 | public function setResourceType(string $type) |
|
225 | |||
226 | /** |
||
227 | * Has resource type defined ? |
||
228 | * |
||
229 | * @return bool |
||
230 | */ |
||
231 | 2 | public function hasResourceType(): bool |
|
235 | |||
236 | /** |
||
237 | * Get type of resource |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | 2 | public function getResourceType(): string |
|
245 | } |