1 | <?php |
||
54 | abstract class AbstractObject implements ObjectInterface |
||
55 | { |
||
56 | /** |
||
57 | * System properties |
||
58 | * |
||
59 | * @var SystemProperties |
||
60 | */ |
||
61 | protected $_systemProperties; |
||
62 | /** |
||
63 | * Meta properties |
||
64 | * |
||
65 | * @var MetaProperties |
||
66 | */ |
||
67 | protected $_metaProperties; |
||
68 | /** |
||
69 | * Domain properties |
||
70 | * |
||
71 | * @var AbstractDomainProperties |
||
72 | */ |
||
73 | protected $_domainProperties; |
||
74 | /** |
||
75 | * Object relations |
||
76 | * |
||
77 | * @var Relations |
||
78 | */ |
||
79 | private $_relations; |
||
80 | /** |
||
81 | * Processing instructions |
||
82 | * |
||
83 | * @var ProcessingInstructions |
||
84 | */ |
||
85 | private $_processingInstructions; |
||
86 | /** |
||
87 | * Object payload |
||
88 | * |
||
89 | * @var string |
||
90 | */ |
||
91 | protected $_payload; |
||
92 | /** |
||
93 | * Repository path |
||
94 | * |
||
95 | * @var RepositoryPathInterface |
||
96 | */ |
||
97 | protected $_path; |
||
98 | /** |
||
99 | * Domain property collection class |
||
100 | * |
||
101 | * @var string |
||
102 | */ |
||
103 | protected $_domainPropertyCollectionClass = null; |
||
104 | |||
105 | /** |
||
106 | * Object constructor |
||
107 | * |
||
108 | * @param RepositoryPathInterface $path Object repository path |
||
109 | * @param array $propertyData Property data |
||
110 | * @param string $payload Object payload |
||
111 | * @throws PropertyInvalidArgumentException If the domain property collection class is invalid |
||
112 | */ |
||
113 | 4 | public function __construct(RepositoryPathInterface $path, array $propertyData = [], $payload = '') |
|
114 | { |
||
115 | // If the domain property collection class is invalid |
||
116 | 4 | if (!is_subclass_of($this->_domainPropertyCollectionClass, AbstractDomainProperties::class)) { |
|
117 | 1 | throw new PropertyInvalidArgumentException( |
|
118 | 1 | sprintf( |
|
119 | 1 | 'Invalid domain property collection class "%s"', |
|
120 | 1 | $this->_domainPropertyCollectionClass |
|
121 | 1 | ), |
|
122 | PropertyInvalidArgumentException::INVALID_DOMAIN_PROPERTY_COLLECTION_CLASS |
||
123 | 1 | ); |
|
124 | } |
||
125 | |||
126 | 3 | $this->_payload = $payload; |
|
127 | 3 | $this->_path = $path; |
|
128 | |||
129 | // Instantiate the system properties |
||
130 | 3 | $systemPropertyData = (empty($propertyData[SystemProperties::COLLECTION]) || !is_array( |
|
131 | 3 | $propertyData[SystemProperties::COLLECTION] |
|
132 | 3 | )) ? [] : $propertyData[SystemProperties::COLLECTION]; |
|
133 | 3 | $this->_systemProperties = new SystemProperties($systemPropertyData, $this); |
|
134 | |||
135 | // Instantiate the meta properties |
||
136 | 2 | $metaPropertyData = (empty($propertyData[MetaProperties::COLLECTION]) || !is_array( |
|
137 | 2 | $propertyData[MetaProperties::COLLECTION] |
|
138 | 2 | )) ? [] : $propertyData[MetaProperties::COLLECTION]; |
|
139 | 2 | $this->_metaProperties = new MetaProperties($metaPropertyData, $this); |
|
140 | |||
141 | // Instantiate the domain properties |
||
142 | 1 | $domainPropertyData = (empty($propertyData[AbstractDomainProperties::COLLECTION]) || !is_array( |
|
143 | 1 | $propertyData[AbstractDomainProperties::COLLECTION] |
|
144 | 1 | )) ? [] : $propertyData[AbstractDomainProperties::COLLECTION]; |
|
145 | 1 | $this->_domainProperties = new $this->_domainPropertyCollectionClass($domainPropertyData, $this); |
|
146 | |||
147 | // Instantiate the processing instructions |
||
148 | 1 | $processingInstructionData = (empty($propertyData[ProcessingInstructions::COLLECTION]) || !is_array( |
|
149 | 1 | $propertyData[ProcessingInstructions::COLLECTION] |
|
150 | 1 | )) ? [] : $propertyData[ProcessingInstructions::COLLECTION]; |
|
151 | 1 | $this->_processingInstructions = new ProcessingInstructions($processingInstructionData, $this); |
|
152 | |||
153 | // Instantiate the object relations |
||
154 | 1 | $relationData = (empty($propertyData[Relations::COLLECTION]) || !is_array( |
|
155 | 1 | $propertyData[Relations::COLLECTION] |
|
156 | 1 | )) ? [] : $propertyData[Relations::COLLECTION]; |
|
157 | 1 | $this->_relations = new Relations($relationData, $this); |
|
158 | 1 | } |
|
159 | |||
160 | /** |
||
161 | * Return the object ID |
||
162 | * |
||
163 | * @return Id Object ID |
||
164 | */ |
||
165 | 1 | public function getId() |
|
166 | { |
||
167 | 1 | return $this->_systemProperties->getId(); |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * Return the object type |
||
172 | * |
||
173 | * @return Type Object type |
||
174 | */ |
||
175 | 1 | public function getType() |
|
176 | { |
||
177 | 1 | return $this->_systemProperties->getType(); |
|
178 | } |
||
179 | |||
180 | /** |
||
181 | * Return the object revision |
||
182 | * |
||
183 | * @return Revision Object revision |
||
184 | */ |
||
185 | 1 | public function getRevision() |
|
186 | { |
||
187 | 1 | return $this->_systemProperties->getRevision(); |
|
188 | } |
||
189 | |||
190 | /** |
||
191 | * Return the creation date & time |
||
192 | * |
||
193 | * @return \DateTimeImmutable Creation date & time |
||
194 | */ |
||
195 | 1 | public function getCreated() |
|
196 | { |
||
197 | 1 | return $this->_systemProperties->getCreated(); |
|
198 | } |
||
199 | |||
200 | /** |
||
201 | * Return the publication date & time |
||
202 | * |
||
203 | * @return \DateTimeImmutable Publication date & time |
||
204 | */ |
||
205 | 1 | public function getPublished() |
|
206 | { |
||
207 | 1 | return $this->_systemProperties->getPublished(); |
|
208 | } |
||
209 | |||
210 | /** |
||
211 | * Return the object description |
||
212 | * |
||
213 | * @return string Object description |
||
214 | */ |
||
215 | 1 | public function getDescription() |
|
219 | |||
220 | /** |
||
221 | * Return the object abstract |
||
222 | * |
||
223 | * @return string Object abstract |
||
224 | */ |
||
225 | 1 | public function getAbstract() |
|
229 | |||
230 | |||
231 | /** |
||
232 | * Return all object keywords |
||
233 | * |
||
234 | * @return array Object keywords |
||
235 | */ |
||
236 | 1 | public function getKeywords() |
|
240 | |||
241 | /** |
||
242 | * Return all object categories |
||
243 | * |
||
244 | * @return array Object categories |
||
245 | */ |
||
246 | 1 | public function getCategories() |
|
250 | |||
251 | /** |
||
252 | * Return all object authors |
||
253 | * |
||
254 | * @return AuthorInterface[] Authors |
||
255 | */ |
||
256 | 2 | public function getAuthors() |
|
260 | |||
261 | /** |
||
262 | * Add an object author |
||
263 | * |
||
264 | * @param AuthorInterface $author Author |
||
265 | * @return ObjectInterface Self reference |
||
266 | */ |
||
267 | 1 | public function addAuthor(AuthorInterface $author) |
|
268 | { |
||
269 | 1 | $authors = $this->_metaProperties->getAuthors(); |
|
270 | 1 | $authors[] = $author; |
|
271 | 1 | $this->_metaProperties->setAuthors($authors); |
|
272 | 1 | return $this; |
|
273 | } |
||
274 | |||
275 | /** |
||
276 | * Return the object repository path |
||
277 | * |
||
278 | * @return RepositoryPathInterface Object repository path |
||
279 | */ |
||
280 | 1 | public function getRepositoryPath() |
|
284 | |||
285 | /** |
||
286 | * Return the absolute object URL |
||
287 | * |
||
288 | * @return string |
||
289 | */ |
||
290 | 1 | public function getAbsoluteUrl() |
|
291 | { |
||
294 | } |
||
295 |