1 | <?php |
||
23 | final class PropertyMetadata |
||
24 | { |
||
25 | private $type; |
||
26 | private $description; |
||
27 | private $readable; |
||
28 | private $writable; |
||
29 | private $readableLink; |
||
30 | private $writableLink; |
||
31 | private $required; |
||
32 | private $iri; |
||
33 | private $identifier; |
||
34 | private $childInherited; |
||
35 | private $attributes; |
||
36 | private $subresource; |
||
37 | |||
38 | public function __construct(Type $type = null, string $description = null, bool $readable = null, bool $writable = null, bool $readableLink = null, bool $writableLink = null, bool $required = null, bool $identifier = null, string $iri = null, $childInherited = null, array $attributes = null, SubresourceMetadata $subresource = null) |
||
53 | |||
54 | /** |
||
55 | * Gets type. |
||
56 | * |
||
57 | * @return Type|null |
||
58 | */ |
||
59 | public function getType() |
||
63 | |||
64 | /** |
||
65 | * Returns a new instance with the given type. |
||
66 | * |
||
67 | * @param Type $type |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | public function withType(Type $type): self |
||
78 | |||
79 | /** |
||
80 | * Gets description. |
||
81 | * |
||
82 | * @return string|null |
||
83 | */ |
||
84 | public function getDescription() |
||
88 | |||
89 | /** |
||
90 | * Returns a new instance with the given description. |
||
91 | * |
||
92 | * @param string $description |
||
93 | * |
||
94 | * @return self |
||
95 | */ |
||
96 | public function withDescription($description): self |
||
103 | |||
104 | /** |
||
105 | * Is readable? |
||
106 | * |
||
107 | * @return bool|null |
||
108 | */ |
||
109 | public function isReadable() |
||
113 | |||
114 | /** |
||
115 | * Returns a new instance of Metadata with the given readable flag. |
||
116 | * |
||
117 | * @param bool $readable |
||
118 | * |
||
119 | * @return self |
||
120 | */ |
||
121 | public function withReadable(bool $readable): self |
||
128 | |||
129 | /** |
||
130 | * Is writable? |
||
131 | * |
||
132 | * @return bool|null |
||
133 | */ |
||
134 | public function isWritable() |
||
138 | |||
139 | /** |
||
140 | * Returns a new instance with the given writable flag. |
||
141 | * |
||
142 | * @param bool $writable |
||
143 | * |
||
144 | * @return self |
||
145 | */ |
||
146 | public function withWritable(bool $writable): self |
||
153 | |||
154 | /** |
||
155 | * Is required? |
||
156 | * |
||
157 | * @return bool|null |
||
158 | */ |
||
159 | public function isRequired() |
||
167 | |||
168 | /** |
||
169 | * Returns a new instance with the given required flag. |
||
170 | * |
||
171 | * @param bool $required |
||
172 | * |
||
173 | * @return self |
||
174 | */ |
||
175 | public function withRequired(bool $required): self |
||
182 | |||
183 | /** |
||
184 | * Should an IRI or an object be provided in write context? |
||
185 | * |
||
186 | * @return bool|null |
||
187 | */ |
||
188 | public function isWritableLink() |
||
192 | |||
193 | /** |
||
194 | * Returns a new instance with the given writable link flag. |
||
195 | * |
||
196 | * @param bool $writableLink |
||
197 | * |
||
198 | * @return self |
||
199 | */ |
||
200 | public function withWritableLink(bool $writableLink): self |
||
207 | |||
208 | /** |
||
209 | * Is an IRI or an object generated in read context? |
||
210 | * |
||
211 | * @return bool|null |
||
212 | */ |
||
213 | public function isReadableLink() |
||
217 | |||
218 | /** |
||
219 | * Returns a new instance with the given readable link flag. |
||
220 | * |
||
221 | * @param bool $readableLink |
||
222 | * |
||
223 | * @return self |
||
224 | */ |
||
225 | public function withReadableLink(bool $readableLink): self |
||
232 | |||
233 | /** |
||
234 | * Gets IRI of this property. |
||
235 | * |
||
236 | * @return string|null |
||
237 | */ |
||
238 | public function getIri() |
||
242 | |||
243 | /** |
||
244 | * Returns a new instance with the given IRI. |
||
245 | * |
||
246 | * @param string|null $iri |
||
247 | * |
||
248 | * @return self |
||
249 | */ |
||
250 | public function withIri(string $iri = null): self |
||
257 | |||
258 | /** |
||
259 | * Is this attribute an identifier? |
||
260 | * |
||
261 | * @return bool|null |
||
262 | */ |
||
263 | public function isIdentifier() |
||
267 | |||
268 | /** |
||
269 | * Returns a new instance with the given identifier flag. |
||
270 | * |
||
271 | * @param bool $identifier |
||
272 | * |
||
273 | * @return self |
||
274 | */ |
||
275 | public function withIdentifier(bool $identifier): self |
||
282 | |||
283 | /** |
||
284 | * Gets attributes. |
||
285 | * |
||
286 | * @return array|null |
||
287 | */ |
||
288 | public function getAttributes() |
||
292 | |||
293 | /** |
||
294 | * Gets an attribute. |
||
295 | * |
||
296 | * @param string $key |
||
297 | * @param mixed $defaultValue |
||
298 | * |
||
299 | * @return mixed |
||
300 | */ |
||
301 | public function getAttribute(string $key, $defaultValue = null) |
||
302 | { |
||
303 | if (isset($this->attributes[$key])) { |
||
304 | return $this->attributes[$key]; |
||
305 | } |
||
306 | |||
307 | return $defaultValue; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * Returns a new instance with the given attribute. |
||
312 | * |
||
313 | * @param array $attributes |
||
314 | * |
||
315 | * @return self |
||
316 | */ |
||
317 | public function withAttributes(array $attributes): self |
||
318 | { |
||
319 | $metadata = clone $this; |
||
320 | $metadata->attributes = $attributes; |
||
321 | |||
322 | return $metadata; |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * Is the property inherited from a child class? |
||
327 | * |
||
328 | * @return string|null |
||
329 | */ |
||
330 | public function isChildInherited() |
||
334 | |||
335 | /** |
||
336 | * Returns a new instance with the given child inherited class. |
||
337 | * |
||
338 | * @param string $childInherited |
||
339 | * |
||
340 | * @return self |
||
341 | */ |
||
342 | public function withChildInherited(string $childInherited): self |
||
349 | |||
350 | /** |
||
351 | * Represents whether the property has a subresource. |
||
352 | * |
||
353 | * @return bool |
||
354 | */ |
||
355 | public function hasSubresource(): bool |
||
359 | |||
360 | /** |
||
361 | * Gets the subresource metadata. |
||
362 | * |
||
363 | * @return SubresourceMetadata|null |
||
364 | */ |
||
365 | public function getSubresource() |
||
369 | |||
370 | /** |
||
371 | * Returns a new instance with the given subresource. |
||
372 | * |
||
373 | * @param SubresourceMetadata $subresource |
||
374 | * |
||
375 | * @return self |
||
376 | */ |
||
377 | public function withSubresource(SubresourceMetadata $subresource = null): self |
||
384 | } |
||
385 |