1 | <?php |
||
21 | final class ResourceMetadata |
||
22 | { |
||
23 | private $shortName; |
||
24 | private $description; |
||
25 | private $iri; |
||
26 | private $itemOperations; |
||
27 | private $collectionOperations; |
||
28 | private $attributes; |
||
29 | |||
30 | public function __construct(string $shortName = null, string $description = null, string $iri = null, array $itemOperations = null, array $collectionOperations = null, array $attributes = null) |
||
39 | |||
40 | /** |
||
41 | * Gets the short name. |
||
42 | * |
||
43 | * @return string|null |
||
44 | */ |
||
45 | public function getShortName() |
||
49 | |||
50 | /** |
||
51 | * Returns a new instance with the given short name. |
||
52 | * |
||
53 | * @param string $shortName |
||
54 | * |
||
55 | * @return self |
||
56 | */ |
||
57 | public function withShortName(string $shortName): self |
||
64 | |||
65 | /** |
||
66 | * Gets the description. |
||
67 | * |
||
68 | * @return string|null |
||
69 | */ |
||
70 | public function getDescription() |
||
74 | |||
75 | /** |
||
76 | * Returns a new instance with the given description. |
||
77 | * |
||
78 | * @param string $description |
||
79 | * |
||
80 | * @return self |
||
81 | */ |
||
82 | public function withDescription(string $description): self |
||
89 | |||
90 | /** |
||
91 | * Gets the associated IRI. |
||
92 | * |
||
93 | * @return string|null |
||
94 | */ |
||
95 | public function getIri() |
||
99 | |||
100 | /** |
||
101 | * Returns a new instance with the given IRI. |
||
102 | * |
||
103 | * @param string $iri |
||
104 | * |
||
105 | * @return self |
||
106 | */ |
||
107 | public function withIri(string $iri): self |
||
114 | |||
115 | /** |
||
116 | * Gets item operations. |
||
117 | * |
||
118 | * @return array|null |
||
119 | */ |
||
120 | public function getItemOperations() |
||
124 | |||
125 | /** |
||
126 | * Returns a new instance with the given item operations. |
||
127 | * |
||
128 | * @param array $itemOperations |
||
129 | * |
||
130 | * @return self |
||
131 | */ |
||
132 | public function withItemOperations(array $itemOperations): self |
||
139 | |||
140 | /** |
||
141 | * Gets collection operations. |
||
142 | * |
||
143 | * @return array|null |
||
144 | */ |
||
145 | public function getCollectionOperations() |
||
149 | |||
150 | /** |
||
151 | * Returns a new instance with the given collection operations. |
||
152 | * |
||
153 | * @param array $collectionOperations |
||
154 | * |
||
155 | * @return self |
||
156 | */ |
||
157 | public function withCollectionOperations(array $collectionOperations): self |
||
164 | |||
165 | /** |
||
166 | * Gets a collection operation attribute, optionally fallback to a resource attribute. |
||
167 | * |
||
168 | * @param string|null $operationName |
||
169 | * @param string $key |
||
170 | * @param mixed $defaultValue |
||
171 | * @param bool $resourceFallback |
||
172 | * |
||
173 | * @return mixed |
||
174 | */ |
||
175 | public function getCollectionOperationAttribute(string $operationName = null, string $key, $defaultValue = null, bool $resourceFallback = false) |
||
179 | |||
180 | /** |
||
181 | * Gets an item operation attribute, optionally fallback to a resource attribute. |
||
182 | * |
||
183 | * @param string|null $operationName |
||
184 | * @param string $key |
||
185 | * @param mixed $defaultValue |
||
186 | * @param bool $resourceFallback |
||
187 | * |
||
188 | * @return mixed |
||
189 | */ |
||
190 | public function getItemOperationAttribute(string $operationName = null, string $key, $defaultValue = null, bool $resourceFallback = false) |
||
194 | |||
195 | /** |
||
196 | * Gets an operation attribute, optionally fallback to a resource attribute. |
||
197 | * |
||
198 | * @param array|null $operations |
||
199 | * @param string|null $operationName |
||
200 | * @param string $key |
||
201 | * @param mixed $defaultValue |
||
202 | * @param bool $resourceFallback |
||
203 | * |
||
204 | * @return mixed |
||
205 | */ |
||
206 | private function getOperationAttribute(array $operations = null, string $operationName = null, string $key, $defaultValue = null, bool $resourceFallback = false) |
||
207 | { |
||
208 | if (null !== $operationName && isset($operations[$operationName][$key])) { |
||
209 | return $operations[$operationName][$key]; |
||
210 | } |
||
211 | |||
212 | if ($resourceFallback && isset($this->attributes[$key])) { |
||
213 | return $this->attributes[$key]; |
||
214 | } |
||
215 | |||
216 | return $defaultValue; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Gets attributes. |
||
221 | * |
||
222 | * @return array|null |
||
223 | */ |
||
224 | public function getAttributes() |
||
228 | |||
229 | /** |
||
230 | * Gets an attribute. |
||
231 | * |
||
232 | * @param string $key |
||
233 | * @param mixed $defaultValue |
||
234 | * |
||
235 | * @return mixed |
||
236 | */ |
||
237 | public function getAttribute(string $key, $defaultValue = null) |
||
245 | |||
246 | /** |
||
247 | * Returns a new instance with the given attribute. |
||
248 | * |
||
249 | * @param array $attributes |
||
250 | * |
||
251 | * @return self |
||
252 | */ |
||
253 | public function withAttributes(array $attributes): self |
||
260 | } |
||
261 |