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 | 2 | public function __construct(RepositoryPathInterface $path, array $propertyData = [], $payload = '') |
|
114 | { |
||
115 | // If the domain property collection class is invalid |
||
116 | 2 | if (!is_subclass_of($this->_domainPropertyCollectionClass, AbstractDomainProperties::class)) { |
|
117 | throw new PropertyInvalidArgumentException( |
||
118 | sprintf( |
||
119 | 'Invalid domain property collection class "%s"', |
||
120 | $this->_domainPropertyCollectionClass |
||
121 | ), |
||
122 | PropertyInvalidArgumentException::INVALID_DOMAIN_PROPERTY_COLLECTION_CLASS |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | 2 | $this->_payload = $payload; |
|
127 | 2 | $this->_path = $path; |
|
128 | |||
129 | // Instantiate the system properties |
||
130 | 2 | $systemPropertyData = (empty($propertyData[SystemProperties::COLLECTION]) || !is_array( |
|
131 | 2 | $propertyData[SystemProperties::COLLECTION] |
|
132 | 2 | )) ? [] : $propertyData[SystemProperties::COLLECTION]; |
|
133 | 2 | $this->_systemProperties = new SystemProperties($systemPropertyData, $this); |
|
134 | |||
135 | // Instantiate the meta properties |
||
136 | 1 | $metaPropertyData = (empty($propertyData[MetaProperties::COLLECTION]) || !is_array( |
|
137 | 1 | $propertyData[MetaProperties::COLLECTION] |
|
138 | 1 | )) ? [] : $propertyData[MetaProperties::COLLECTION]; |
|
139 | 1 | $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 | public function getId() |
||
169 | |||
170 | /** |
||
171 | * Return the object type |
||
172 | * |
||
173 | * @return Type Object type |
||
174 | */ |
||
175 | public function getType() |
||
179 | |||
180 | /** |
||
181 | * Return the object revision |
||
182 | * |
||
183 | * @return Revision Object revision |
||
184 | */ |
||
185 | public function getRevision() |
||
189 | |||
190 | /** |
||
191 | * Return the creation date & time |
||
192 | * |
||
193 | * @return \DateTimeImmutable Creation date & time |
||
194 | */ |
||
195 | public function getCreated() |
||
199 | |||
200 | /** |
||
201 | * Return the publication date & time |
||
202 | * |
||
203 | * @return \DateTimeImmutable Publication date & time |
||
204 | */ |
||
205 | public function getPublished() |
||
209 | |||
210 | /** |
||
211 | * Return all object keywords |
||
212 | * |
||
213 | * @return array Object keywords |
||
214 | */ |
||
215 | 1 | public function getKeywords() |
|
219 | |||
220 | /** |
||
221 | * Return all object categories |
||
222 | * |
||
223 | * @return array Object categories |
||
224 | */ |
||
225 | 1 | public function getCategories() |
|
229 | |||
230 | /** |
||
231 | * Return all object authors |
||
232 | * |
||
233 | * @return AuthorInterface[] Authors |
||
234 | */ |
||
235 | 1 | public function getAuthors() |
|
239 | |||
240 | /** |
||
241 | * Add an object author |
||
242 | * |
||
243 | * @param AuthorInterface $author Author |
||
244 | * @return ObjectInterface Self reference |
||
245 | */ |
||
246 | public function addAuthor(AuthorInterface $author) |
||
253 | |||
254 | /** |
||
255 | * Return the object repository path |
||
256 | * |
||
257 | * @return RepositoryPathInterface Object repository path |
||
258 | */ |
||
259 | 1 | public function getRepositoryPath() |
|
263 | |||
264 | /** |
||
265 | * Return the absolute object URL |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | public function getAbsoluteUrl() |
||
273 | } |
||
274 |