|
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\Factory\AuthorFactory; |
|
40
|
|
|
use Apparat\Object\Domain\Model\Author\AuthorInterface; |
|
41
|
|
|
use Apparat\Object\Domain\Model\Object\ObjectInterface; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Meta object properties collection |
|
45
|
|
|
* |
|
46
|
|
|
* @package Apparat\Object |
|
47
|
|
|
* @subpackage Apparat\Object\Application |
|
48
|
|
|
*/ |
|
49
|
|
|
class MetaProperties extends AbstractProperties |
|
50
|
|
|
{ |
|
51
|
|
|
/** |
|
52
|
|
|
* Object description |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $_description = ''; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Object abstract |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $_abstract = ''; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Object keywords |
|
67
|
|
|
* |
|
68
|
|
|
* @var array |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $_keywords = []; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Object categories |
|
74
|
|
|
* |
|
75
|
|
|
* @var array |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $_categories = []; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Object authors |
|
81
|
|
|
* |
|
82
|
|
|
* @var AuthorInterface[] |
|
83
|
|
|
*/ |
|
84
|
|
|
protected $_authors = []; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Collection name |
|
88
|
|
|
* |
|
89
|
|
|
* @var string |
|
90
|
|
|
*/ |
|
91
|
|
|
const COLLECTION = 'meta'; |
|
92
|
|
|
|
|
93
|
|
|
/******************************************************************************* |
|
94
|
|
|
* PUBLIC METHODS |
|
95
|
|
|
*******************************************************************************/ |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Meta properties constructor |
|
99
|
|
|
* |
|
100
|
|
|
* @param array $data Property data |
|
101
|
|
|
* @param ObjectInterface $object Owner object |
|
102
|
|
|
*/ |
|
103
|
2 |
|
public function __construct(array $data, ObjectInterface $object) |
|
104
|
|
|
{ |
|
105
|
2 |
|
parent::__construct($data, $object); |
|
106
|
|
|
|
|
107
|
|
|
// Initialize the description |
|
108
|
2 |
|
if (array_key_exists('description', $data)) { |
|
109
|
2 |
|
$this->setDescription($data['description']); |
|
110
|
2 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
// Initialize the abstract |
|
113
|
2 |
|
if (array_key_exists('abstract', $data)) { |
|
114
|
2 |
|
$this->setAbstract($data['abstract']); |
|
115
|
2 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
// Initialize the keywords |
|
118
|
2 |
|
if (array_key_exists('keywords', $data)) { |
|
119
|
1 |
|
$this->setKeywords((array)$data['keywords']); |
|
120
|
1 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
// Initialize the categories |
|
123
|
2 |
|
if (array_key_exists('categories', $data)) { |
|
124
|
1 |
|
$this->setCategories((array)$data['categories']); |
|
125
|
1 |
|
} |
|
126
|
|
|
|
|
127
|
|
|
// Initialize the authors |
|
128
|
2 |
|
if (array_key_exists('authors', $data)) { |
|
129
|
2 |
|
$this->setAuthors($data['authors']); |
|
130
|
1 |
|
} |
|
131
|
1 |
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Return the object description |
|
135
|
|
|
* |
|
136
|
|
|
* @return string Object description |
|
137
|
|
|
*/ |
|
138
|
1 |
|
public function getDescription() |
|
139
|
|
|
{ |
|
140
|
1 |
|
return $this->_description; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Set the object description |
|
145
|
|
|
* |
|
146
|
|
|
* @param string $description Object description |
|
147
|
|
|
* @return MetaProperties Self reference |
|
148
|
|
|
*/ |
|
149
|
2 |
|
public function setDescription($description) |
|
150
|
|
|
{ |
|
151
|
2 |
|
$this->_description = $description; |
|
152
|
2 |
|
return $this; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Return the object abstract |
|
157
|
|
|
* |
|
158
|
|
|
* @return string Object abstract |
|
159
|
|
|
*/ |
|
160
|
1 |
|
public function getAbstract() |
|
161
|
|
|
{ |
|
162
|
1 |
|
return $this->_abstract; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Set the object abstract |
|
167
|
|
|
* |
|
168
|
|
|
* @param string $abstract Object abstract |
|
169
|
|
|
* @return MetaProperties Self reference |
|
170
|
|
|
*/ |
|
171
|
2 |
|
public function setAbstract($abstract) |
|
172
|
|
|
{ |
|
173
|
2 |
|
$this->_abstract = $abstract; |
|
174
|
2 |
|
return $this; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Return the object keywords |
|
179
|
|
|
* |
|
180
|
|
|
* @return array Object keywords |
|
181
|
|
|
*/ |
|
182
|
1 |
|
public function getKeywords() |
|
183
|
|
|
{ |
|
184
|
1 |
|
return $this->_keywords; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Set the object keywords |
|
189
|
|
|
* |
|
190
|
|
|
* @param array $keywords Object keywords |
|
191
|
|
|
* @return MetaProperties Self reference |
|
192
|
|
|
*/ |
|
193
|
1 |
|
public function setKeywords(array $keywords) |
|
194
|
|
|
{ |
|
195
|
1 |
|
$this->_keywords = array_unique($keywords); |
|
196
|
1 |
|
sort($this->_keywords, SORT_NATURAL); |
|
197
|
1 |
|
return $this; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Return the object categories |
|
202
|
|
|
* |
|
203
|
|
|
* @return array Object categories |
|
204
|
|
|
*/ |
|
205
|
1 |
|
public function getCategories() |
|
206
|
|
|
{ |
|
207
|
1 |
|
return $this->_categories; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Set the object categories |
|
212
|
|
|
* |
|
213
|
|
|
* @param array $categories Object categories |
|
214
|
|
|
* @return MetaProperties Self reference |
|
215
|
|
|
*/ |
|
216
|
1 |
|
public function setCategories(array $categories) |
|
217
|
|
|
{ |
|
218
|
1 |
|
$this->_categories = array_unique($categories); |
|
219
|
1 |
|
sort($this->_categories, SORT_NATURAL); |
|
220
|
1 |
|
return $this; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Return the object authors |
|
225
|
|
|
* |
|
226
|
|
|
* @return AuthorInterface[] |
|
227
|
|
|
*/ |
|
228
|
1 |
|
public function getAuthors() |
|
229
|
|
|
{ |
|
230
|
1 |
|
return $this->_authors; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Set the object authors |
|
235
|
|
|
* |
|
236
|
|
|
* @param array $authors Object authors |
|
237
|
|
|
* @return MetaProperties Self reference |
|
238
|
|
|
* @throws InvalidArgumentException If an author is invalid |
|
239
|
|
|
*/ |
|
240
|
2 |
|
public function setAuthors(array $authors) |
|
241
|
|
|
{ |
|
242
|
2 |
|
$newAuthors = []; |
|
243
|
|
|
|
|
244
|
|
|
// Run through and validate all authors |
|
245
|
2 |
|
foreach ($authors as $author) { |
|
246
|
|
|
|
|
247
|
|
|
// If the author is invalid |
|
248
|
2 |
|
if (is_string($author)) { |
|
249
|
1 |
|
$author = AuthorFactory::createFromString( |
|
250
|
1 |
|
$author, |
|
251
|
1 |
|
$this->getObject()->getRepositoryPath()->getRepository() |
|
252
|
1 |
|
); |
|
253
|
1 |
|
} |
|
254
|
|
|
|
|
255
|
|
|
// If the author is invalid |
|
256
|
2 |
|
if (!$author instanceof AuthorInterface) { |
|
257
|
1 |
|
throw new InvalidArgumentException( |
|
258
|
1 |
|
'Invalid object author', |
|
259
|
|
|
InvalidArgumentException::INVALID_OBJECT_AUTHOR |
|
260
|
1 |
|
); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
1 |
|
$newAuthors[$author->getSignature()] = $author; |
|
264
|
1 |
|
} |
|
265
|
|
|
|
|
266
|
1 |
|
$this->_authors = array_values($newAuthors); |
|
|
|
|
|
|
267
|
1 |
|
return $this; |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|