1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* apparat-object |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Object |
8
|
|
|
* @subpackage Apparat\Object\Application |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Apparat\Object\Domain\Model\Properties; |
38
|
|
|
|
39
|
|
|
use Apparat\Object\Domain\Model\Object\ObjectInterface; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Meta object properties collection |
43
|
|
|
* |
44
|
|
|
* @package Apparat\Object |
45
|
|
|
* @subpackage Apparat\Object\Domain |
46
|
|
|
*/ |
47
|
|
|
class MetaProperties extends AbstractProperties |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* Collection name |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
const COLLECTION = 'meta'; |
55
|
|
|
/** |
56
|
|
|
* Title property |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
const PROPERTY_TITLE = 'title'; |
61
|
|
|
/** |
62
|
|
|
* Slug property |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
const PROPERTY_SLUG = 'slug'; |
67
|
|
|
/** |
68
|
|
|
* Description property |
69
|
|
|
* |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
const PROPERTY_DESCRIPTION = 'description'; |
73
|
|
|
/** |
74
|
|
|
* Abstract property |
75
|
|
|
* |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
const PROPERTY_ABSTRACT = 'abstract'; |
79
|
|
|
/** |
80
|
|
|
* License property |
81
|
|
|
* |
82
|
|
|
* @var string |
83
|
|
|
*/ |
84
|
|
|
const PROPERTY_LICENSE = 'license'; |
85
|
|
|
/** |
86
|
|
|
* Privacy property |
87
|
|
|
* |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
const PROPERTY_PRIVACY = 'privacy'; |
91
|
|
|
/** |
92
|
|
|
* Keywords property |
93
|
|
|
* |
94
|
|
|
* @var string |
95
|
|
|
*/ |
96
|
|
|
const PROPERTY_KEYWORDS = 'keywords'; |
97
|
|
|
/** |
98
|
|
|
* Categories property |
99
|
|
|
* |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
const PROPERTY_CATEGORIES = 'categories'; |
103
|
|
|
/** |
104
|
|
|
* Private |
105
|
|
|
* |
106
|
|
|
* @var string |
107
|
|
|
*/ |
108
|
|
|
const PRIVACY_PRIVATE = 'private'; |
109
|
|
|
/** |
110
|
|
|
* Public |
111
|
|
|
* |
112
|
|
|
* @var string |
113
|
|
|
*/ |
114
|
|
|
const PRIVACY_PUBLIC = 'public'; |
115
|
|
|
/** |
116
|
|
|
* Privacy levels |
117
|
|
|
* |
118
|
|
|
* @var array |
119
|
|
|
*/ |
120
|
|
|
public static $privacyLevels = [ |
121
|
|
|
self::PRIVACY_PRIVATE, |
122
|
|
|
self::PRIVACY_PUBLIC, |
123
|
|
|
]; |
124
|
|
|
/** |
125
|
|
|
* Object title |
126
|
|
|
* |
127
|
|
|
* @var string |
128
|
|
|
*/ |
129
|
|
|
protected $title = ''; |
130
|
|
|
/** |
131
|
|
|
* Object slug |
132
|
|
|
* |
133
|
|
|
* @var string |
134
|
|
|
*/ |
135
|
|
|
protected $slug = ''; |
136
|
|
|
/** |
137
|
|
|
* Object description |
138
|
|
|
* |
139
|
|
|
* @var string |
140
|
|
|
*/ |
141
|
|
|
protected $description = ''; |
142
|
|
|
/** |
143
|
|
|
* Object abstract |
144
|
|
|
* |
145
|
|
|
* @var string |
146
|
|
|
*/ |
147
|
|
|
protected $abstract = ''; |
148
|
|
|
/** |
149
|
|
|
* Object license |
150
|
|
|
* |
151
|
|
|
* @var string |
152
|
|
|
*/ |
153
|
|
|
protected $license = ''; |
154
|
|
|
/** |
155
|
|
|
* Object privacy |
156
|
|
|
* |
157
|
|
|
* @var string |
158
|
|
|
*/ |
159
|
|
|
protected $privacy = self::PRIVACY_PRIVATE; |
160
|
|
|
/** |
161
|
|
|
* Object keywords |
162
|
|
|
* |
163
|
|
|
* @var array |
164
|
|
|
*/ |
165
|
|
|
protected $keywords = []; |
166
|
|
|
/** |
167
|
|
|
* Object categories |
168
|
|
|
* |
169
|
|
|
* @var array |
170
|
|
|
*/ |
171
|
|
|
protected $categories = []; |
172
|
|
|
|
173
|
|
|
/******************************************************************************* |
174
|
|
|
* PUBLIC METHODS |
175
|
|
|
*******************************************************************************/ |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Meta properties constructor |
179
|
|
|
* |
180
|
|
|
* @param array $data Property data |
181
|
|
|
* @param ObjectInterface $object Owner object |
182
|
|
|
*/ |
183
|
45 |
|
public function __construct(array $data, ObjectInterface $object) |
184
|
|
|
{ |
185
|
45 |
|
parent::__construct($data, $object); |
186
|
|
|
|
187
|
|
|
// Initialize the title |
188
|
45 |
|
if (array_key_exists(self::PROPERTY_TITLE, $data)) { |
189
|
39 |
|
$this->title = $data[self::PROPERTY_TITLE]; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
// Initialize the slug |
193
|
45 |
|
if (array_key_exists(self::PROPERTY_SLUG, $data)) { |
194
|
32 |
|
$this->slug = $data[self::PROPERTY_SLUG]; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
// Initialize the description |
198
|
45 |
|
if (array_key_exists(self::PROPERTY_DESCRIPTION, $data)) { |
199
|
32 |
|
$this->description = $data[self::PROPERTY_DESCRIPTION]; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
// Initialize the abstract |
203
|
45 |
|
if (array_key_exists(self::PROPERTY_ABSTRACT, $data)) { |
204
|
33 |
|
$this->abstract = $data[self::PROPERTY_ABSTRACT]; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
// Initialize the keywords |
208
|
45 |
|
if (array_key_exists(self::PROPERTY_KEYWORDS, $data)) { |
209
|
38 |
|
$this->keywords = $this->normalizeSortedPropertyValues((array)$data[self::PROPERTY_KEYWORDS]); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
// Initialize the categories |
213
|
45 |
|
if (array_key_exists(self::PROPERTY_CATEGORIES, $data)) { |
214
|
38 |
|
$this->categories = $this->normalizeSortedPropertyValues((array)$data[self::PROPERTY_CATEGORIES]); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// Initialize the privacy |
218
|
45 |
|
if (array_key_exists(self::PROPERTY_PRIVACY, $data)) { |
219
|
7 |
|
$this->privacy = $data[self::PROPERTY_PRIVACY]; |
220
|
|
|
} |
221
|
45 |
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Return the object title |
225
|
|
|
* |
226
|
|
|
* @return string Object title |
227
|
|
|
*/ |
228
|
5 |
|
public function getTitle() |
229
|
|
|
{ |
230
|
5 |
|
return $this->title; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Set the object title |
235
|
|
|
* |
236
|
|
|
* @param string $title Object title |
237
|
|
|
* @return MetaProperties Self reference |
238
|
|
|
*/ |
239
|
4 |
|
public function setTitle($title) |
240
|
|
|
{ |
241
|
4 |
|
return $this->mutateStringProperty(self::PROPERTY_TITLE, $title); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Return the object slug |
246
|
|
|
* |
247
|
|
|
* @return string Object slug |
248
|
|
|
*/ |
249
|
1 |
|
public function getSlug() |
250
|
|
|
{ |
251
|
1 |
|
return $this->slug; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Set the object slug |
256
|
|
|
* |
257
|
|
|
* @param string $slug Object slug |
258
|
|
|
* @return MetaProperties Self reference |
259
|
|
|
*/ |
260
|
1 |
|
public function setSlug($slug) |
261
|
|
|
{ |
262
|
1 |
|
return $this->mutateStringProperty(self::PROPERTY_SLUG, $slug); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Return the object description |
267
|
|
|
* |
268
|
|
|
* @return string Object description |
269
|
|
|
*/ |
270
|
2 |
|
public function getDescription() |
271
|
|
|
{ |
272
|
2 |
|
return $this->description; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Set the object description |
277
|
|
|
* |
278
|
|
|
* @param string $description Object description |
279
|
|
|
* @return MetaProperties Self reference |
280
|
|
|
*/ |
281
|
1 |
|
public function setDescription($description) |
282
|
|
|
{ |
283
|
1 |
|
return $this->mutateStringProperty(self::PROPERTY_DESCRIPTION, $description); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Return the object abstract |
288
|
|
|
* |
289
|
|
|
* @return string Object abstract |
290
|
|
|
*/ |
291
|
4 |
|
public function getAbstract() |
292
|
|
|
{ |
293
|
4 |
|
return $this->abstract; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Set the object abstract |
298
|
|
|
* |
299
|
|
|
* @param string $abstract Object abstract |
300
|
|
|
* @return MetaProperties Self reference |
301
|
|
|
*/ |
302
|
2 |
|
public function setAbstract($abstract) |
303
|
|
|
{ |
304
|
2 |
|
return $this->mutateStringProperty(self::PROPERTY_ABSTRACT, $abstract); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Return the object license |
309
|
|
|
* |
310
|
|
|
* @return string Object license |
311
|
|
|
*/ |
312
|
1 |
|
public function getLicense() |
313
|
|
|
{ |
314
|
1 |
|
return $this->license; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Set the object license |
319
|
|
|
* |
320
|
|
|
* @param string $license Object license |
321
|
|
|
* @return MetaProperties Self reference |
322
|
|
|
*/ |
323
|
1 |
|
public function setLicense($license) |
324
|
|
|
{ |
325
|
1 |
|
return $this->mutateStringProperty(self::PROPERTY_LICENSE, $license); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Return the object privacy |
330
|
|
|
* |
331
|
|
|
* @return string Object privacy |
332
|
|
|
*/ |
333
|
2 |
|
public function getPrivacy() |
334
|
|
|
{ |
335
|
2 |
|
return $this->privacy; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Set the object privacy |
340
|
|
|
* |
341
|
|
|
* @param string $privacy Object privacy |
342
|
|
|
* @return MetaProperties Self reference |
343
|
|
|
*/ |
344
|
1 |
|
public function setPrivacy($privacy) |
345
|
|
|
{ |
346
|
|
|
// If the privacy level is unknown |
347
|
1 |
|
if (!in_array($privacy, self::$privacyLevels)) { |
348
|
1 |
|
throw new OutOfBoundsException( |
349
|
1 |
|
sprintf('Invalid privacy level "%s"', $privacy), |
350
|
1 |
|
OutOfBoundsException::INVALID_PRIVACY_LEVEL |
351
|
|
|
); |
352
|
|
|
} |
353
|
|
|
|
354
|
1 |
|
return $this->mutateStringProperty(self::PROPERTY_PRIVACY, $privacy); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Return the object keywords |
359
|
|
|
* |
360
|
|
|
* @return array Object keywords |
361
|
|
|
*/ |
362
|
2 |
|
public function getKeywords() |
363
|
|
|
{ |
364
|
2 |
|
return $this->keywords; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Set the object keywords |
369
|
|
|
* |
370
|
|
|
* @param array $keywords Object keywords |
371
|
|
|
* @return MetaProperties Self reference |
372
|
|
|
*/ |
373
|
1 |
|
public function setKeywords(array $keywords) |
374
|
|
|
{ |
375
|
1 |
|
return $this->mutateListProperty(self::PROPERTY_KEYWORDS, $this->normalizeSortedPropertyValues($keywords)); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Return the object categories |
380
|
|
|
* |
381
|
|
|
* @return array Object categories |
382
|
|
|
*/ |
383
|
3 |
|
public function getCategories() |
384
|
|
|
{ |
385
|
3 |
|
return $this->categories; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Set the object categories |
390
|
|
|
* |
391
|
|
|
* @param array $categories Object categories |
392
|
|
|
* @return MetaProperties Self reference |
393
|
|
|
*/ |
394
|
1 |
|
public function setCategories(array $categories) |
395
|
|
|
{ |
396
|
1 |
|
return $this->mutateListProperty(self::PROPERTY_CATEGORIES, $this->normalizeSortedPropertyValues($categories)); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Return the property values as array |
401
|
|
|
* |
402
|
|
|
* @param bool $serialize Serialize property objects |
403
|
|
|
* @return array Property values |
404
|
|
|
*/ |
405
|
10 |
|
public function toArray($serialize = true) |
406
|
|
|
{ |
407
|
10 |
|
return $this->toSerializedArray( |
408
|
|
|
$serialize, |
409
|
|
|
[ |
410
|
10 |
|
self::PROPERTY_TITLE => $this->title, |
411
|
10 |
|
self::PROPERTY_DESCRIPTION => $this->description, |
412
|
10 |
|
self::PROPERTY_ABSTRACT => $this->abstract, |
413
|
10 |
|
self::PROPERTY_KEYWORDS => $this->keywords, |
414
|
10 |
|
self::PROPERTY_CATEGORIES => $this->categories, |
415
|
|
|
] |
416
|
|
|
); |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
|