1 | <?php |
||
51 | class ObjectProxy implements ObjectInterface |
||
52 | { |
||
53 | /** |
||
54 | * Apparat object URL |
||
55 | * |
||
56 | * @var ApparatUrl |
||
57 | */ |
||
58 | protected $url = null; |
||
59 | /** |
||
60 | * Object |
||
61 | * |
||
62 | * @var ObjectInterface |
||
63 | */ |
||
64 | protected $object = null; |
||
65 | |||
66 | /******************************************************************************* |
||
67 | * PUBLIC METHODS |
||
68 | *******************************************************************************/ |
||
69 | |||
70 | /** |
||
71 | * Object proxy constructor |
||
72 | * |
||
73 | * @param ApparatUrl $url Apparat object URL |
||
74 | */ |
||
75 | 15 | public function __construct(ApparatUrl $url) |
|
79 | |||
80 | /** |
||
81 | * Return the object repository path |
||
82 | * |
||
83 | * @return PathInterface Object repository path |
||
84 | */ |
||
85 | public function getRepositoryPath() |
||
96 | |||
97 | /** |
||
98 | * Return the object property data |
||
99 | * |
||
100 | * @return array Object property data |
||
101 | */ |
||
102 | public function getPropertyData() |
||
106 | |||
107 | /** |
||
108 | * Return the enclosed remote object |
||
109 | * |
||
110 | * @return ObjectInterface Remote object |
||
111 | */ |
||
112 | protected function object() |
||
122 | |||
123 | /** |
||
124 | * Return the object payload |
||
125 | * |
||
126 | * @return string Object payload |
||
127 | */ |
||
128 | public function getPayload() |
||
132 | |||
133 | /** |
||
134 | * Set the payload |
||
135 | * |
||
136 | * @param string $payload Payload |
||
137 | * @return ObjectInterface Self reference |
||
138 | */ |
||
139 | public function setPayload($payload) |
||
143 | |||
144 | /** |
||
145 | * Return the object ID |
||
146 | * |
||
147 | * @return Id Object ID |
||
148 | */ |
||
149 | public function getId() |
||
153 | |||
154 | /** |
||
155 | * Return the object type |
||
156 | * |
||
157 | * @return Type Object type |
||
158 | */ |
||
159 | public function getType() |
||
163 | |||
164 | /** |
||
165 | * Return the object revision |
||
166 | * |
||
167 | * @return Revision Object revision |
||
168 | */ |
||
169 | public function getRevision() |
||
173 | |||
174 | /** |
||
175 | * Return the object draft mode |
||
176 | * |
||
177 | * @return boolean Object draft mode |
||
178 | */ |
||
179 | public function isDraft() |
||
183 | |||
184 | /** |
||
185 | * Return whether the object is in dirty state |
||
186 | * |
||
187 | * @return boolean Dirty state |
||
188 | */ |
||
189 | public function isDirty() |
||
193 | |||
194 | /** |
||
195 | * Return whether the object is in mutated state |
||
196 | * |
||
197 | * @return boolean Mutated state |
||
198 | */ |
||
199 | public function isMutated() |
||
203 | |||
204 | /** |
||
205 | * Return the creation date & time |
||
206 | * |
||
207 | * @return \DateTimeImmutable Creation date & time |
||
208 | */ |
||
209 | public function getCreated() |
||
213 | |||
214 | /** |
||
215 | * Return the publication date & time |
||
216 | * |
||
217 | * @return \DateTimeImmutable Publication date & time |
||
218 | */ |
||
219 | public function getPublished() |
||
223 | |||
224 | /** |
||
225 | * Return the object hash |
||
226 | * |
||
227 | * @return string Object hash |
||
228 | */ |
||
229 | public function getHash() |
||
233 | |||
234 | /** |
||
235 | * Return the object description |
||
236 | * |
||
237 | * @return string Object description |
||
238 | */ |
||
239 | public function getDescription() |
||
243 | |||
244 | /** |
||
245 | * Set the description |
||
246 | * |
||
247 | * @param string $description Description |
||
248 | * @return ObjectInterface Self reference |
||
249 | */ |
||
250 | public function setDescription($description) |
||
254 | |||
255 | /** |
||
256 | * Return the object abstract |
||
257 | * |
||
258 | * @return string Object abstract |
||
259 | */ |
||
260 | public function getAbstract() |
||
264 | |||
265 | /** |
||
266 | * Set the abstract |
||
267 | * |
||
268 | * @param string $abstract Abstract |
||
269 | * @return ObjectInterface Self reference |
||
270 | */ |
||
271 | public function setAbstract($abstract) |
||
275 | |||
276 | /** |
||
277 | * Return all object keywords |
||
278 | * |
||
279 | * @return array Object keywords |
||
280 | */ |
||
281 | public function getKeywords() |
||
285 | |||
286 | /** |
||
287 | * Set the keywords |
||
288 | * |
||
289 | * @param array $keywords Keywords |
||
290 | * @return ObjectInterface Self reference |
||
291 | */ |
||
292 | public function setKeywords(array $keywords) |
||
296 | |||
297 | /** |
||
298 | * Return all object categories |
||
299 | * |
||
300 | * @return array Object categories |
||
301 | */ |
||
302 | public function getCategories() |
||
306 | |||
307 | /** |
||
308 | * Set the categories |
||
309 | * |
||
310 | * @param array $categories Categories |
||
311 | * @return ObjectInterface Self reference |
||
312 | */ |
||
313 | public function setCategories(array $categories) |
||
317 | |||
318 | /** |
||
319 | * Return all object authors |
||
320 | * |
||
321 | * @return AuthorInterface[] Authors |
||
322 | */ |
||
323 | public function getAuthors() |
||
327 | |||
328 | /** |
||
329 | * Add an object author |
||
330 | * |
||
331 | * @param AuthorInterface $author Author |
||
332 | * @return ObjectInterface Self reference |
||
333 | */ |
||
334 | public function addAuthor(AuthorInterface $author) |
||
338 | |||
339 | /** |
||
340 | * Get a domain property value |
||
341 | * |
||
342 | * Multi-level properties might be traversed by property name paths separated with colons (":"). |
||
343 | * |
||
344 | * @param string $property Property name |
||
345 | * @return mixed Property value |
||
346 | */ |
||
347 | public function getDomainProperty($property) |
||
351 | |||
352 | /** |
||
353 | * Set a domain property value |
||
354 | * |
||
355 | * @param string $property Property name |
||
356 | * @param mixed $value Property value |
||
357 | * @return ObjectInterface Self reference |
||
358 | */ |
||
359 | public function setDomainProperty($property, $value) |
||
363 | |||
364 | /** |
||
365 | * Get a processing instruction |
||
366 | * |
||
367 | * @param string $procInst Processing instruction name |
||
368 | * @return mixed Processing instruction |
||
369 | */ |
||
370 | public function getProcessingInstruction($procInst) |
||
374 | |||
375 | /** |
||
376 | * Set a processing instruction |
||
377 | * |
||
378 | * @param string $procInst Processing instruction name |
||
379 | * @param mixed $value Processing instruction |
||
380 | * @return ObjectInterface Self reference |
||
381 | */ |
||
382 | public function setProcessingInstruction($procInst, $value) |
||
386 | |||
387 | /** |
||
388 | * Return the absolute object URL |
||
389 | * |
||
390 | * @return string |
||
391 | */ |
||
392 | 14 | public function getAbsoluteUrl() |
|
396 | |||
397 | /** |
||
398 | * Generic caller |
||
399 | * |
||
400 | * @param string $name Method name |
||
401 | * @param array $arguments Method arguments |
||
402 | */ |
||
403 | public function __call($name, $arguments) |
||
415 | |||
416 | /** |
||
417 | * Use a specific object revision |
||
418 | * |
||
419 | * @param Revision $revision Revision to be used |
||
420 | * @return ObjectInterface Object |
||
421 | */ |
||
422 | public function useRevision(Revision $revision) |
||
426 | |||
427 | /** |
||
428 | * Persist the current object revision |
||
429 | * |
||
430 | * @return ObjectInterface Object |
||
431 | */ |
||
432 | public function persist() |
||
436 | } |
||
437 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.