1 | <?php |
||
57 | abstract class AbstractObject implements ObjectInterface |
||
58 | { |
||
59 | /** |
||
60 | * System properties |
||
61 | * |
||
62 | * @var SystemProperties |
||
63 | */ |
||
64 | protected $systemProperties; |
||
65 | /** |
||
66 | * Meta properties |
||
67 | * |
||
68 | * @var MetaProperties |
||
69 | */ |
||
70 | protected $metaProperties; |
||
71 | /** |
||
72 | * Domain properties |
||
73 | * |
||
74 | * @var AbstractDomainProperties |
||
75 | */ |
||
76 | protected $domainProperties; |
||
77 | /** |
||
78 | * Object payload |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | protected $payload; |
||
83 | /** |
||
84 | * Repository path |
||
85 | * |
||
86 | * @var RepositoryPathInterface |
||
87 | */ |
||
88 | protected $path; |
||
89 | /** |
||
90 | * Domain property collection class |
||
91 | * |
||
92 | * @var string |
||
93 | */ |
||
94 | protected $domainPropertyCClass = AbstractDomainProperties::class; |
||
95 | /** |
||
96 | * Object relations |
||
97 | * |
||
98 | * @var Relations |
||
99 | */ |
||
100 | protected $relations; |
||
101 | /** |
||
102 | * Processing instructions |
||
103 | * |
||
104 | * @var ProcessingInstructions |
||
105 | */ |
||
106 | protected $processingInstructions; |
||
107 | /** |
||
108 | * Latest revision index |
||
109 | * |
||
110 | * @var Revision |
||
111 | */ |
||
112 | protected $latestRevision; |
||
113 | |||
114 | /** |
||
115 | * Object constructor |
||
116 | * |
||
117 | * @param string $payload Object payload |
||
118 | * @param array $propertyData Property data |
||
119 | * @param RepositoryPathInterface $path Object repository path |
||
120 | */ |
||
121 | 18 | public function __construct($payload = '', array $propertyData = [], RepositoryPathInterface $path = null) |
|
122 | { |
||
123 | // If the domain property collection class is invalid |
||
124 | 18 | if (!$this->domainPropertyCClass |
|
125 | 18 | || !class_exists($this->domainPropertyCClass) |
|
126 | 18 | || !(new \ReflectionClass($this->domainPropertyCClass))->isSubclassOf(AbstractDomainProperties::class) |
|
127 | ) { |
||
128 | 1 | throw new PropertyInvalidArgumentException( |
|
129 | sprintf( |
||
130 | 1 | 'Invalid domain property collection class "%s"', |
|
131 | 1 | $this->domainPropertyCClass |
|
132 | ), |
||
133 | 1 | PropertyInvalidArgumentException::INVALID_DOMAIN_PROPERTY_COLLECTION_CLASS |
|
134 | ); |
||
135 | } |
||
136 | |||
137 | 17 | $this->path = $path; |
|
138 | |||
139 | // Load the current revision data |
||
140 | 17 | $this->loadRevisionData($payload, $propertyData); |
|
141 | |||
142 | // Save the latest revision index |
||
143 | 15 | $this->latestRevision = $this->getRevision(); |
|
144 | 15 | } |
|
145 | |||
146 | /** |
||
147 | * Load object revision data |
||
148 | * |
||
149 | * @param string $payload Object payload |
||
150 | * @param array $propertyData Property data |
||
151 | */ |
||
152 | 17 | protected function loadRevisionData($payload = '', array $propertyData = []) |
|
191 | |||
192 | /** |
||
193 | * Return the object revision |
||
194 | * |
||
195 | * @return Revision Object revision |
||
196 | */ |
||
197 | 15 | public function getRevision() |
|
201 | |||
202 | /** |
||
203 | * Use a specific object revision |
||
204 | * |
||
205 | * @param Revision $revision Revision to be used |
||
206 | * @return ObjectInterface Object |
||
207 | * @throws OutOfBoundsException If the requested revision is invalid |
||
208 | */ |
||
209 | 14 | public function useRevision(Revision $revision) |
|
249 | |||
250 | /** |
||
251 | * Return the object ID |
||
252 | * |
||
253 | * @return Id Object ID |
||
254 | */ |
||
255 | 5 | public function getId() |
|
259 | |||
260 | /** |
||
261 | * Return the object type |
||
262 | * |
||
263 | * @return Type Object type |
||
264 | */ |
||
265 | 1 | public function getType() |
|
269 | |||
270 | /** |
||
271 | * Return the creation date & time |
||
272 | * |
||
273 | * @return \DateTimeImmutable Creation date & time |
||
274 | */ |
||
275 | 1 | public function getCreated() |
|
279 | |||
280 | /** |
||
281 | * Return the publication date & time |
||
282 | * |
||
283 | * @return \DateTimeImmutable Publication date & time |
||
284 | */ |
||
285 | 1 | public function getPublished() |
|
289 | |||
290 | /** |
||
291 | * Return the object hash |
||
292 | * |
||
293 | * @return string Object hash |
||
294 | */ |
||
295 | 1 | public function getHash() |
|
299 | |||
300 | /** |
||
301 | * Return the object description |
||
302 | * |
||
303 | * @return string Object description |
||
304 | */ |
||
305 | 1 | public function getDescription() |
|
309 | |||
310 | /** |
||
311 | * Return the object abstract |
||
312 | * |
||
313 | * @return string Object abstract |
||
314 | */ |
||
315 | 1 | public function getAbstract() |
|
319 | |||
320 | /** |
||
321 | * Return all object keywords |
||
322 | * |
||
323 | * @return array Object keywords |
||
324 | */ |
||
325 | 1 | public function getKeywords() |
|
329 | |||
330 | /** |
||
331 | * Return all object categories |
||
332 | * |
||
333 | * @return array Object categories |
||
334 | */ |
||
335 | 1 | public function getCategories() |
|
339 | |||
340 | /** |
||
341 | * Return all object authors |
||
342 | * |
||
343 | * @return AuthorInterface[] Authors |
||
344 | */ |
||
345 | 2 | public function getAuthors() |
|
349 | |||
350 | /** |
||
351 | * Add an object author |
||
352 | * |
||
353 | * @param AuthorInterface $author Author |
||
354 | * @return ObjectInterface Self reference |
||
355 | */ |
||
356 | 1 | public function addAuthor(AuthorInterface $author) |
|
363 | |||
364 | /** |
||
365 | * Return the object repository path |
||
366 | * |
||
367 | * @return RepositoryPathInterface Object repository path |
||
368 | */ |
||
369 | 15 | public function getRepositoryPath() |
|
373 | |||
374 | /** |
||
375 | * Return the object property data |
||
376 | * |
||
377 | * @return array Object property data |
||
378 | */ |
||
379 | 2 | public function getPropertyData() |
|
393 | |||
394 | /** |
||
395 | * Return the object payload |
||
396 | * |
||
397 | * @return string Object payload |
||
398 | */ |
||
399 | 2 | public function getPayload() |
|
403 | |||
404 | /** |
||
405 | * Return the absolute object URL |
||
406 | * |
||
407 | * @return string |
||
408 | */ |
||
409 | 1 | public function getAbsoluteUrl() |
|
413 | |||
414 | /** |
||
415 | * Get a particular property value |
||
416 | * |
||
417 | * Multi-level properties might be traversed by property name paths separated with colons (":"). |
||
418 | * |
||
419 | * @param string $property Property name |
||
420 | * @return mixed Property value |
||
421 | */ |
||
422 | 2 | public function getDomainProperty($property) |
|
426 | } |
||
427 |