|
1
|
|
|
<?php |
|
2
|
|
|
namespace Dkd\PhpCmis\Converter; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file is part of php-cmis-lib. |
|
6
|
|
|
* |
|
7
|
|
|
* (c) Sascha Egerer <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
use function array_diff_key; |
|
14
|
|
|
use function array_filter; |
|
15
|
|
|
use function array_flip; |
|
16
|
|
|
use function array_map; |
|
17
|
|
|
use function array_walk; |
|
18
|
|
|
use Dkd\Enumeration\Exception\InvalidEnumerationValueException; |
|
19
|
|
|
use Dkd\PhpCmis\Bindings\Browser\JSONConstants; |
|
20
|
|
|
use Dkd\PhpCmis\Converter\Types\TypeConverterInterface; |
|
21
|
|
|
use Dkd\PhpCmis\Data\AclCapabilitiesInterface; |
|
22
|
|
|
use Dkd\PhpCmis\Data\AclInterface; |
|
23
|
|
|
use Dkd\PhpCmis\Data\AllowableActionsInterface; |
|
24
|
|
|
use Dkd\PhpCmis\Data\ExtensionFeatureInterface; |
|
25
|
|
|
use Dkd\PhpCmis\Data\ObjectDataInterface; |
|
26
|
|
|
use Dkd\PhpCmis\Data\ObjectInFolderContainerInterface; |
|
27
|
|
|
use Dkd\PhpCmis\Data\ObjectInFolderDataInterface; |
|
28
|
|
|
use Dkd\PhpCmis\Data\ObjectInFolderListInterface; |
|
29
|
|
|
use Dkd\PhpCmis\Data\ObjectListInterface; |
|
30
|
|
|
use Dkd\PhpCmis\Data\ObjectParentDataInterface; |
|
31
|
|
|
use Dkd\PhpCmis\Data\PropertiesInterface; |
|
32
|
|
|
use Dkd\PhpCmis\Data\PropertyDataInterface; |
|
33
|
|
|
use Dkd\PhpCmis\Data\RenditionDataInterface; |
|
34
|
|
|
use Dkd\PhpCmis\Data\RepositoryCapabilitiesInterface; |
|
35
|
|
|
use Dkd\PhpCmis\Data\RepositoryInfoInterface; |
|
36
|
|
|
use Dkd\PhpCmis\DataObjects\AbstractTypeDefinition; |
|
37
|
|
|
use Dkd\PhpCmis\DataObjects\AccessControlEntry; |
|
38
|
|
|
use Dkd\PhpCmis\DataObjects\AccessControlList; |
|
39
|
|
|
use Dkd\PhpCmis\DataObjects\AclCapabilities; |
|
40
|
|
|
use Dkd\PhpCmis\DataObjects\AllowableActions; |
|
41
|
|
|
use Dkd\PhpCmis\DataObjects\BindingsObjectFactory; |
|
42
|
|
|
use Dkd\PhpCmis\DataObjects\ChangeEventInfo; |
|
43
|
|
|
use Dkd\PhpCmis\DataObjects\CmisExtensionElement; |
|
44
|
|
|
use Dkd\PhpCmis\DataObjects\CreatablePropertyTypes; |
|
45
|
|
|
use Dkd\PhpCmis\DataObjects\ExtensionFeature; |
|
46
|
|
|
use Dkd\PhpCmis\DataObjects\FailedToDeleteData; |
|
47
|
|
|
use Dkd\PhpCmis\DataObjects\NewTypeSettableAttributes; |
|
48
|
|
|
use Dkd\PhpCmis\DataObjects\ObjectData; |
|
49
|
|
|
use Dkd\PhpCmis\DataObjects\ObjectInFolderContainer; |
|
50
|
|
|
use Dkd\PhpCmis\DataObjects\ObjectInFolderData; |
|
51
|
|
|
use Dkd\PhpCmis\DataObjects\ObjectInFolderList; |
|
52
|
|
|
use Dkd\PhpCmis\DataObjects\ObjectList; |
|
53
|
|
|
use Dkd\PhpCmis\DataObjects\ObjectParentData; |
|
54
|
|
|
use Dkd\PhpCmis\DataObjects\PermissionDefinition; |
|
55
|
|
|
use Dkd\PhpCmis\DataObjects\PermissionMapping; |
|
56
|
|
|
use Dkd\PhpCmis\DataObjects\PolicyIdList; |
|
57
|
|
|
use Dkd\PhpCmis\DataObjects\Principal; |
|
58
|
|
|
use Dkd\PhpCmis\DataObjects\Properties; |
|
59
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyBoolean; |
|
60
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyBooleanDefinition; |
|
61
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyDateTime; |
|
62
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyDateTimeDefinition; |
|
63
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyDecimal; |
|
64
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyDecimalDefinition; |
|
65
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyHtml; |
|
66
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyHtmlDefinition; |
|
67
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyId; |
|
68
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyIdDefinition; |
|
69
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyInteger; |
|
70
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyIntegerDefinition; |
|
71
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyString; |
|
72
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyStringDefinition; |
|
73
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyUri; |
|
74
|
|
|
use Dkd\PhpCmis\DataObjects\PropertyUriDefinition; |
|
75
|
|
|
use Dkd\PhpCmis\DataObjects\RenditionData; |
|
76
|
|
|
use Dkd\PhpCmis\DataObjects\RepositoryCapabilities; |
|
77
|
|
|
use Dkd\PhpCmis\DataObjects\RepositoryInfoBrowserBinding; |
|
78
|
|
|
use Dkd\PhpCmis\DataObjects\TypeDefinitionContainer; |
|
79
|
|
|
use Dkd\PhpCmis\DataObjects\TypeDefinitionList; |
|
80
|
|
|
use Dkd\PhpCmis\DataObjects\TypeMutability; |
|
81
|
|
|
use Dkd\PhpCmis\Definitions\MutableDocumentTypeDefinitionInterface; |
|
82
|
|
|
use Dkd\PhpCmis\Definitions\MutableRelationshipTypeDefinitionInterface; |
|
83
|
|
|
use Dkd\PhpCmis\Definitions\MutableTypeDefinitionInterface; |
|
84
|
|
|
use Dkd\PhpCmis\Definitions\PropertyDefinitionInterface; |
|
85
|
|
|
use Dkd\PhpCmis\Definitions\RelationshipTypeDefinitionInterface; |
|
86
|
|
|
use Dkd\PhpCmis\Definitions\TypeDefinitionContainerInterface; |
|
87
|
|
|
use Dkd\PhpCmis\Definitions\TypeDefinitionInterface; |
|
88
|
|
|
use Dkd\PhpCmis\Definitions\TypeDefinitionListInterface; |
|
89
|
|
|
use Dkd\PhpCmis\Enum\AclPropagation; |
|
90
|
|
|
use Dkd\PhpCmis\Enum\Action; |
|
91
|
|
|
use Dkd\PhpCmis\Enum\BaseTypeId; |
|
92
|
|
|
use Dkd\PhpCmis\Enum\CapabilityAcl; |
|
93
|
|
|
use Dkd\PhpCmis\Enum\CapabilityChanges; |
|
94
|
|
|
use Dkd\PhpCmis\Enum\CapabilityContentStreamUpdates; |
|
95
|
|
|
use Dkd\PhpCmis\Enum\CapabilityJoin; |
|
96
|
|
|
use Dkd\PhpCmis\Enum\CapabilityOrderBy; |
|
97
|
|
|
use Dkd\PhpCmis\Enum\CapabilityQuery; |
|
98
|
|
|
use Dkd\PhpCmis\Enum\CapabilityRenditions; |
|
99
|
|
|
use Dkd\PhpCmis\Enum\Cardinality; |
|
100
|
|
|
use Dkd\PhpCmis\Enum\ChangeType; |
|
101
|
|
|
use Dkd\PhpCmis\Enum\CmisVersion; |
|
102
|
|
|
use Dkd\PhpCmis\Enum\ContentStreamAllowed; |
|
103
|
|
|
use Dkd\PhpCmis\Enum\DateTimeResolution; |
|
104
|
|
|
use Dkd\PhpCmis\Enum\DecimalPrecision; |
|
105
|
|
|
use Dkd\PhpCmis\Enum\PropertyType; |
|
106
|
|
|
use Dkd\PhpCmis\Enum\SupportedPermissions; |
|
107
|
|
|
use Dkd\PhpCmis\Enum\Updatability; |
|
108
|
|
|
use Dkd\PhpCmis\Exception\CmisInvalidArgumentException; |
|
109
|
|
|
use Dkd\PhpCmis\Exception\CmisRuntimeException; |
|
110
|
|
|
use function is_array; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Convert PHP CMIS Objects to JSON and JSON Responses TO PHP CMIS Objects |
|
114
|
|
|
* |
|
115
|
|
|
* @TODO: To reduce the complexity of this class there should be some kind of schema mapping in the future. |
|
116
|
|
|
*/ |
|
117
|
2 |
|
class JsonConverter extends AbstractDataConverter |
|
118
|
|
|
{ |
|
119
|
2 |
|
/** |
|
120
|
1 |
|
* @param array|null $data |
|
121
|
|
|
* @return AllowableActions|null |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function convertAllowableActions(array $data = null) |
|
124
|
1 |
|
{ |
|
125
|
1 |
|
if (empty($data)) { |
|
126
|
|
|
return null; |
|
127
|
1 |
|
} |
|
128
|
|
|
|
|
129
|
1 |
|
$allowableActions = new AllowableActions(); |
|
130
|
1 |
|
$actions = []; |
|
131
|
1 |
|
$extensions = []; |
|
132
|
1 |
|
|
|
133
|
1 |
|
foreach ($data as $key => $value) { |
|
134
|
|
|
try { |
|
135
|
1 |
|
if ((boolean) $value === true) { |
|
136
|
|
|
$actions[] = Action::cast($key); |
|
137
|
1 |
|
} |
|
138
|
1 |
|
} catch (InvalidEnumerationValueException $exception) { |
|
139
|
|
|
$extensions[$key] = $value; |
|
140
|
1 |
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$allowableActions->setAllowableActions($actions); |
|
144
|
|
|
$allowableActions->setExtensions($this->convertExtension($extensions)); |
|
145
|
|
|
|
|
146
|
|
|
return $allowableActions; |
|
147
|
2 |
|
} |
|
148
|
|
|
|
|
149
|
2 |
|
/** |
|
150
|
1 |
|
* @param array|null $data The JSON that contains the repository info |
|
151
|
|
|
* @return null|RepositoryInfoBrowserBinding |
|
152
|
|
|
*/ |
|
153
|
1 |
|
public function convertRepositoryInfo(array $data = null) |
|
154
|
|
|
{ |
|
155
|
|
|
return empty($data) ? null : $this->setRepositoryInfoValues(new RepositoryInfoBrowserBinding(), $data); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param RepositoryInfoBrowserBinding $object |
|
160
|
|
|
* @param array $data |
|
161
|
1 |
|
* @return RepositoryInfoBrowserBinding |
|
162
|
|
|
*/ |
|
163
|
1 |
|
protected function setRepositoryInfoValues(RepositoryInfoBrowserBinding $object, $data) |
|
164
|
1 |
|
{ |
|
165
|
1 |
|
$data[JSONConstants::JSON_REPINFO_CAPABILITIES] = $this->convertRepositoryCapabilities( |
|
166
|
1 |
|
$data[JSONConstants::JSON_REPINFO_CAPABILITIES] ?? null |
|
167
|
1 |
|
); |
|
168
|
1 |
|
|
|
169
|
1 |
|
$data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES] = $this->convertAclCapabilities( |
|
170
|
1 |
|
$data[JSONConstants::JSON_REPINFO_ACL_CAPABILITIES] ?? null |
|
|
|
|
|
|
171
|
1 |
|
); |
|
172
|
|
|
|
|
173
|
|
|
$data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE] = array_map( |
|
174
|
1 |
|
function ($item) { return BaseTypeId::cast($item); }, |
|
175
|
|
|
array_filter( |
|
176
|
1 |
|
$data[JSONConstants::JSON_REPINFO_CHANGES_ON_TYPE] ?? [], |
|
177
|
1 |
|
function ($item) { return !empty($item); } |
|
178
|
1 |
|
) |
|
179
|
1 |
|
); |
|
180
|
1 |
|
|
|
181
|
1 |
|
$data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES] = $this->convertExtensionFeatures( |
|
182
|
1 |
|
$data[JSONConstants::JSON_REPINFO_EXTENDED_FEATURES] ?? [] |
|
|
|
|
|
|
183
|
|
|
); |
|
184
|
|
|
|
|
185
|
1 |
|
if (isset($data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED])) { |
|
186
|
|
|
$data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED] = CmisVersion::cast( |
|
187
|
1 |
|
$data[JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED] |
|
188
|
1 |
|
); |
|
189
|
1 |
|
} |
|
190
|
1 |
|
|
|
191
|
1 |
|
$data = array_filter($data, function ($item) { return $item !== null; }); |
|
192
|
1 |
|
|
|
193
|
1 |
|
$object->setExtensions($this->convertExtension($data, JSONConstants::getRepositoryInfoKeys())); |
|
194
|
1 |
|
|
|
195
|
1 |
|
$object->populate( |
|
196
|
|
|
$data, |
|
197
|
1 |
|
array_merge( |
|
198
|
1 |
|
array_combine(JSONConstants::getRepositoryInfoKeys(), JSONConstants::getRepositoryInfoKeys()), |
|
199
|
|
|
[ |
|
200
|
1 |
|
JSONConstants::JSON_REPINFO_DESCRIPTION => 'description', |
|
201
|
1 |
|
JSONConstants::JSON_REPINFO_CMIS_VERSION_SUPPORTED => 'cmisVersion', |
|
202
|
1 |
|
JSONConstants::JSON_REPINFO_ID => 'id', |
|
203
|
1 |
|
JSONConstants::JSON_REPINFO_ROOT_FOLDER_URL => 'rootUrl', |
|
204
|
1 |
|
JSONConstants::JSON_REPINFO_NAME => 'name', |
|
205
|
1 |
|
JSONConstants::JSON_REPINFO_EXTENDED_FEATURES => 'extensionFeatures' |
|
206
|
1 |
|
] |
|
207
|
|
|
), |
|
208
|
1 |
|
true |
|
209
|
1 |
|
); |
|
210
|
1 |
|
|
|
211
|
1 |
|
return $object; |
|
212
|
1 |
|
} |
|
213
|
|
|
|
|
214
|
1 |
|
/** |
|
215
|
|
|
* @param array|null $data |
|
216
|
1 |
|
* @return RepositoryCapabilities|null |
|
217
|
1 |
|
*/ |
|
218
|
1 |
|
public function convertRepositoryCapabilities(array $data = null) |
|
219
|
1 |
|
{ |
|
220
|
|
|
if (empty($data)) { |
|
221
|
1 |
|
return null; |
|
222
|
1 |
|
} |
|
223
|
1 |
|
|
|
224
|
1 |
|
if (isset($data[JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY])) { |
|
225
|
1 |
|
$data[JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY] = CapabilityContentStreamUpdates::cast( |
|
226
|
1 |
|
$data[JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY] |
|
227
|
1 |
|
); |
|
228
|
1 |
|
} |
|
229
|
|
|
if (isset($data[JSONConstants::JSON_CAP_CHANGES])) { |
|
230
|
1 |
|
$data[JSONConstants::JSON_CAP_CHANGES] = CapabilityChanges::cast($data[JSONConstants::JSON_CAP_CHANGES]); |
|
231
|
|
|
} |
|
232
|
1 |
|
if (isset($data[JSONConstants::JSON_CAP_RENDITIONS])) { |
|
233
|
|
|
$data[JSONConstants::JSON_CAP_RENDITIONS] = CapabilityRenditions::cast( |
|
234
|
|
|
$data[JSONConstants::JSON_CAP_RENDITIONS] |
|
235
|
|
|
); |
|
236
|
|
|
} |
|
237
|
|
|
if (isset($data[JSONConstants::JSON_CAP_ORDER_BY])) { |
|
238
|
|
|
$data[JSONConstants::JSON_CAP_ORDER_BY] = CapabilityOrderBy::cast( |
|
239
|
2 |
|
$data[JSONConstants::JSON_CAP_ORDER_BY] |
|
240
|
|
|
); |
|
241
|
2 |
|
} |
|
242
|
1 |
|
if (isset($data[JSONConstants::JSON_CAP_QUERY])) { |
|
243
|
|
|
$data[JSONConstants::JSON_CAP_QUERY] = CapabilityQuery::cast($data[JSONConstants::JSON_CAP_QUERY]); |
|
244
|
|
|
} |
|
245
|
1 |
|
if (isset($data[JSONConstants::JSON_CAP_JOIN])) { |
|
246
|
1 |
|
$data[JSONConstants::JSON_CAP_JOIN] = CapabilityJoin::cast($data[JSONConstants::JSON_CAP_JOIN]); |
|
247
|
1 |
|
} |
|
248
|
1 |
|
if (isset($data[JSONConstants::JSON_CAP_ACL])) { |
|
249
|
1 |
|
$data[JSONConstants::JSON_CAP_ACL] = CapabilityAcl::cast($data[JSONConstants::JSON_CAP_ACL]); |
|
250
|
1 |
|
} |
|
251
|
1 |
|
|
|
252
|
1 |
|
if (isset($data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES])) { |
|
253
|
1 |
|
$data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES] = $this->convertCreatablePropertyTypes( |
|
254
|
1 |
|
$data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES] |
|
255
|
1 |
|
); |
|
256
|
1 |
|
} |
|
257
|
1 |
|
|
|
258
|
1 |
|
if (isset($data[JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES])) { |
|
259
|
1 |
|
$data[JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES] = $this->convertNewTypeSettableAttributes( |
|
260
|
1 |
|
$data[JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES] |
|
261
|
1 |
|
); |
|
262
|
1 |
|
} |
|
263
|
1 |
|
|
|
264
|
1 |
|
$data = array_filter($data, function ($item) { return $item !== null; }); |
|
265
|
1 |
|
|
|
266
|
1 |
|
$repositoryCapabilities = new RepositoryCapabilities(); |
|
267
|
1 |
|
$repositoryCapabilities->setExtensions($this->convertExtension($data, JSONConstants::getCapabilityKeys())); |
|
268
|
1 |
|
|
|
269
|
1 |
|
$repositoryCapabilities->populate( |
|
270
|
1 |
|
$data, |
|
271
|
1 |
|
array_merge( |
|
272
|
|
|
array_combine(JSONConstants::getCapabilityKeys(), JSONConstants::getCapabilityKeys()), |
|
273
|
1 |
|
[ |
|
274
|
1 |
|
JSONConstants::JSON_CAP_CONTENT_STREAM_UPDATABILITY => 'contentStreamUpdatesCapability', |
|
275
|
1 |
|
JSONConstants::JSON_CAP_CHANGES => 'changesCapability', |
|
276
|
1 |
|
JSONConstants::JSON_CAP_RENDITIONS => 'renditionsCapability', |
|
277
|
1 |
|
JSONConstants::JSON_CAP_GET_DESCENDANTS => 'supportsGetDescendants', |
|
278
|
|
|
JSONConstants::JSON_CAP_GET_FOLDER_TREE => 'supportsGetFolderTree', |
|
279
|
|
|
JSONConstants::JSON_CAP_MULTIFILING => 'supportsMultifiling', |
|
280
|
1 |
|
JSONConstants::JSON_CAP_UNFILING => 'supportsUnfiling', |
|
281
|
|
|
JSONConstants::JSON_CAP_VERSION_SPECIFIC_FILING => 'supportsVersionSpecificFiling', |
|
282
|
1 |
|
JSONConstants::JSON_CAP_PWC_SEARCHABLE => 'supportsPwcSearchable', |
|
283
|
1 |
|
JSONConstants::JSON_CAP_PWC_UPDATABLE => 'supportsPwcUpdatable', |
|
284
|
1 |
|
JSONConstants::JSON_CAP_ALL_VERSIONS_SEARCHABLE => 'supportsAllVersionsSearchable', |
|
285
|
1 |
|
JSONConstants::JSON_CAP_ORDER_BY => 'orderByCapability', |
|
286
|
1 |
|
JSONConstants::JSON_CAP_QUERY => 'queryCapability', |
|
287
|
|
|
JSONConstants::JSON_CAP_JOIN => 'joinCapability', |
|
288
|
|
|
JSONConstants::JSON_CAP_ACL => 'aclCapability', |
|
289
|
1 |
|
JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES => 'creatablePropertyTypes', |
|
290
|
|
|
JSONConstants::JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES => 'newTypeSettableAttributes' |
|
291
|
1 |
|
] |
|
292
|
1 |
|
), |
|
293
|
|
|
true |
|
294
|
1 |
|
); |
|
295
|
1 |
|
|
|
296
|
1 |
|
return $repositoryCapabilities; |
|
297
|
1 |
|
} |
|
298
|
|
|
|
|
299
|
1 |
|
/** |
|
300
|
1 |
|
* Create NewTypeSettableAttributes object and populate given data to it |
|
301
|
1 |
|
* |
|
302
|
1 |
|
* @param string[]|null $data |
|
303
|
1 |
|
* @return NewTypeSettableAttributes|null Returns object or <code>null</code> if given data is empty |
|
304
|
1 |
|
*/ |
|
305
|
1 |
View Code Duplication |
public function convertNewTypeSettableAttributes(array $data = null) |
|
306
|
1 |
|
{ |
|
307
|
1 |
|
if (empty($data)) { |
|
308
|
1 |
|
return null; |
|
309
|
1 |
|
} |
|
310
|
1 |
|
$object = new NewTypeSettableAttributes(); |
|
311
|
1 |
|
|
|
312
|
1 |
|
$object->populate( |
|
313
|
1 |
|
$data, |
|
314
|
1 |
|
array_combine( |
|
315
|
1 |
|
JSONConstants::getCapabilityNewTypeSettableAttributeKeys(), |
|
316
|
1 |
|
array_map( |
|
317
|
1 |
|
function ($key) { |
|
318
|
|
|
// add a prefix "canSet" to all keys as this are the property names |
|
319
|
1 |
|
return 'canSet' . ucfirst($key); |
|
320
|
|
|
}, |
|
321
|
1 |
|
JSONConstants::getCapabilityNewTypeSettableAttributeKeys() |
|
322
|
|
|
) |
|
323
|
|
|
), |
|
324
|
|
|
true |
|
325
|
|
|
); |
|
326
|
|
|
|
|
327
|
|
|
$object->setExtensions( |
|
328
|
|
|
$this->convertExtension( |
|
329
|
|
|
$data, |
|
330
|
1 |
|
JSONConstants::getCapabilityNewTypeSettableAttributeKeys() |
|
331
|
|
|
) |
|
332
|
1 |
|
); |
|
333
|
|
|
|
|
334
|
|
|
return $object; |
|
335
|
1 |
|
} |
|
336
|
|
|
|
|
337
|
1 |
|
/** |
|
338
|
1 |
|
* Create CreatablePropertyTypes object and populate given data to it |
|
339
|
1 |
|
* |
|
340
|
1 |
|
* @param array|null $data The data that should be populated to the CreatablePropertyTypes object |
|
341
|
1 |
|
* @return CreatablePropertyTypes|null Returns a CreatablePropertyTypes object or <code>null</code> if empty data |
|
342
|
|
|
* is given. |
|
343
|
|
|
*/ |
|
344
|
1 |
|
public function convertCreatablePropertyTypes(array $data = null) |
|
345
|
1 |
|
{ |
|
346
|
1 |
|
if (empty($data)) { |
|
347
|
1 |
|
return null; |
|
348
|
1 |
|
} |
|
349
|
|
|
|
|
350
|
1 |
|
$object = new CreatablePropertyTypes(); |
|
351
|
|
|
|
|
352
|
1 |
|
foreach ($data[JSONConstants::JSON_CAP_CREATABLE_PROPERTY_TYPES_CANCREATE] ?? [] as $canCreateItem) { |
|
353
|
1 |
|
try { |
|
354
|
1 |
|
$canCreate[] = PropertyType::cast($canCreateItem); |
|
|
|
|
|
|
355
|
1 |
|
} catch (InvalidEnumerationValueException $exception) { |
|
356
|
1 |
|
// ignore invalid types |
|
357
|
1 |
|
} |
|
358
|
|
|
} |
|
359
|
1 |
|
|
|
360
|
|
|
$object->setCanCreate($canCreate); |
|
|
|
|
|
|
361
|
|
|
|
|
362
|
|
|
$object->setExtensions( |
|
363
|
|
|
$this->convertExtension( |
|
364
|
|
|
$data, |
|
365
|
|
|
JSONConstants::getCapabilityCreatablePropertyKeys() |
|
366
|
|
|
) |
|
367
|
|
|
); |
|
368
|
|
|
|
|
369
|
1 |
|
return $object; |
|
370
|
|
|
} |
|
371
|
1 |
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* @param array|null $data |
|
374
|
|
|
* @param boolean $isExact |
|
375
|
1 |
|
* @return AccessControlList |
|
376
|
|
|
*/ |
|
377
|
1 |
|
public function convertAcl(array $data = null, $isExact = false) |
|
378
|
1 |
|
{ |
|
379
|
1 |
|
if (empty($data)) { |
|
380
|
1 |
|
return null; |
|
381
|
|
|
} |
|
382
|
1 |
|
|
|
383
|
|
|
$aces = []; |
|
384
|
1 |
|
if (isset($data[JSONConstants::JSON_ACL_ACES]) && is_array($data[JSONConstants::JSON_ACL_ACES])) { |
|
385
|
1 |
|
foreach ($data[JSONConstants::JSON_ACL_ACES] as $aceData) { |
|
386
|
|
|
if (empty($aceData[JSONConstants::JSON_ACE_PRINCIPAL][JSONConstants::JSON_ACE_PRINCIPAL_ID])) { |
|
387
|
|
|
continue; |
|
388
|
1 |
|
} |
|
389
|
|
|
|
|
390
|
1 |
|
$permissions = array_filter( |
|
391
|
1 |
|
$aceData[JSONConstants::JSON_ACE_PERMISSIONS] ?? [], |
|
392
|
|
|
function($item) { return !empty($item); } |
|
393
|
1 |
|
); |
|
394
|
1 |
|
|
|
395
|
1 |
|
$principal = new Principal( |
|
396
|
1 |
|
(string) $aceData[JSONConstants::JSON_ACE_PRINCIPAL][JSONConstants::JSON_ACE_PRINCIPAL_ID] |
|
397
|
1 |
|
); |
|
398
|
1 |
|
|
|
399
|
|
|
$principal->setExtensions( |
|
400
|
1 |
|
$this->convertExtension( |
|
401
|
|
|
$aceData[JSONConstants::JSON_ACE_PRINCIPAL], |
|
402
|
|
|
JSONConstants::getAcePrincipalKeys() |
|
403
|
|
|
) |
|
404
|
|
|
); |
|
405
|
|
|
|
|
406
|
|
|
$ace = new AccessControlEntry($principal, $permissions); |
|
407
|
|
|
|
|
408
|
3 |
|
if (isset($aceData[JSONConstants::JSON_ACE_IS_DIRECT])) { |
|
409
|
|
|
$ace->setIsDirect((boolean) $aceData[JSONConstants::JSON_ACE_IS_DIRECT] ?? false); |
|
410
|
3 |
|
} |
|
411
|
1 |
|
|
|
412
|
|
|
$ace->setExtensions($this->convertExtension($aceData, JSONConstants::getAceKeys())); |
|
413
|
|
|
|
|
414
|
2 |
|
$aces[] = $ace; |
|
415
|
2 |
|
} |
|
416
|
2 |
|
} |
|
417
|
2 |
|
|
|
418
|
2 |
|
$acl = new AccessControlList($aces); |
|
419
|
|
|
$acl->setIsExact($isExact); |
|
420
|
|
|
$acl->setExtensions($this->convertExtension($data, JSONConstants::getAclKeys())); |
|
421
|
1 |
|
|
|
422
|
1 |
|
return $acl; |
|
423
|
1 |
|
} |
|
424
|
1 |
|
|
|
425
|
1 |
|
/** |
|
426
|
1 |
|
* @param array|null $data |
|
427
|
1 |
|
* @return AclCapabilities|null |
|
428
|
1 |
|
*/ |
|
429
|
1 |
|
public function convertAclCapabilities(array $data = null) |
|
430
|
1 |
|
{ |
|
431
|
|
|
if (empty($data)) { |
|
432
|
1 |
|
return null; |
|
433
|
1 |
|
} |
|
434
|
1 |
|
|
|
435
|
|
|
$aclCapabilities = new AclCapabilities(); |
|
436
|
1 |
|
$aclCapabilities->setSupportedPermissions( |
|
437
|
1 |
|
SupportedPermissions::cast($data[JSONConstants::JSON_ACLCAP_SUPPORTED_PERMISSIONS]) |
|
438
|
1 |
|
); |
|
439
|
1 |
|
$aclCapabilities->setAclPropagation( |
|
440
|
1 |
|
AclPropagation::cast($data[JSONConstants::JSON_ACLCAP_ACL_PROPAGATION]) |
|
441
|
1 |
|
); |
|
442
|
|
|
|
|
443
|
1 |
|
$permissionDefinitionList = []; |
|
444
|
|
|
|
|
445
|
1 |
|
foreach ($data[JSONConstants::JSON_ACLCAP_PERMISSIONS] ?? [] as $permissionData) { |
|
446
|
1 |
|
$permissionDefinition = new PermissionDefinition(); |
|
447
|
1 |
|
|
|
448
|
|
|
$permissionDefinition->setId( |
|
449
|
1 |
|
(string) $permissionData[JSONConstants::JSON_ACLCAP_PERMISSION_PERMISSION] |
|
450
|
|
|
); |
|
451
|
1 |
|
$permissionDefinition->setDescription( |
|
452
|
2 |
|
(string) $permissionData[JSONConstants::JSON_ACLCAP_PERMISSION_DESCRIPTION] |
|
453
|
2 |
|
); |
|
454
|
|
|
|
|
455
|
2 |
|
// handle extensions |
|
456
|
2 |
|
|
|
457
|
2 |
|
$permissionDefinition->setExtensions( |
|
458
|
|
|
$this->convertExtension( |
|
459
|
2 |
|
$permissionData, |
|
460
|
|
|
JSONConstants::getAclCapabilityPermissionKeys() |
|
461
|
|
|
) |
|
462
|
|
|
); |
|
463
|
|
|
|
|
464
|
|
|
$permissionDefinitionList[] = $permissionDefinition; |
|
465
|
|
|
} |
|
466
|
2 |
|
|
|
467
|
|
|
$aclCapabilities->setPermissions($permissionDefinitionList); |
|
468
|
2 |
|
|
|
469
|
1 |
|
$permissionMappingList = []; |
|
470
|
|
|
|
|
471
|
|
|
foreach ($data[JSONConstants::JSON_ACLCAP_PERMISSION_MAPPING] ?? [] as $permissionMapping) { |
|
472
|
1 |
|
$mapping = new PermissionMapping(); |
|
473
|
1 |
|
$key = (string) $permissionMapping[JSONConstants::JSON_ACLCAP_MAPPING_KEY]; |
|
474
|
1 |
|
|
|
475
|
1 |
|
$mapping->setKey($key); |
|
476
|
1 |
|
|
|
477
|
1 |
|
$mapping->setPermissions( |
|
478
|
1 |
|
array_map( |
|
479
|
|
|
'strval', |
|
480
|
1 |
|
array_filter( |
|
481
|
1 |
|
$permissionMapping[JSONConstants::JSON_ACLCAP_MAPPING_PERMISSION] ?? [], |
|
482
|
1 |
|
function ($item) { return !empty($item); } |
|
483
|
1 |
|
) |
|
484
|
1 |
|
) |
|
485
|
|
|
); |
|
486
|
1 |
|
|
|
487
|
1 |
|
$mapping->setExtensions( |
|
488
|
1 |
|
$this->convertExtension($permissionMapping, JSONConstants::getAclCapabilityMappingKeys()) |
|
489
|
|
|
); |
|
490
|
1 |
|
|
|
491
|
1 |
|
$permissionMappingList[$key] = $mapping; |
|
492
|
1 |
|
} |
|
493
|
1 |
|
|
|
494
|
1 |
|
$aclCapabilities->setPermissionMapping($permissionMappingList); |
|
495
|
1 |
|
|
|
496
|
|
|
// handle extensions |
|
497
|
|
|
$aclCapabilities->setExtensions($this->convertExtension($data, JSONConstants::getAclCapabilityKeys())); |
|
498
|
|
|
|
|
499
|
1 |
|
return $aclCapabilities; |
|
500
|
1 |
|
} |
|
501
|
1 |
|
|
|
502
|
1 |
|
/** |
|
503
|
1 |
|
* Convert an array to a type definition object |
|
504
|
1 |
|
* |
|
505
|
|
|
* @param array|null $data |
|
506
|
1 |
|
* @return AbstractTypeDefinition|null |
|
507
|
1 |
|
* @throws CmisInvalidArgumentException |
|
508
|
1 |
|
*/ |
|
509
|
|
|
public function convertTypeDefinition(array $data = null) |
|
510
|
1 |
|
{ |
|
511
|
1 |
|
if (empty($data)) { |
|
512
|
|
|
return null; |
|
513
|
1 |
|
} |
|
514
|
1 |
|
|
|
515
|
1 |
|
if (empty($data[JSONConstants::JSON_TYPE_ID])) { |
|
516
|
1 |
|
throw new CmisInvalidArgumentException('Id of type definition is empty but must not be empty!'); |
|
517
|
1 |
|
} |
|
518
|
|
|
$typeDefinition = $this->getBindingsObjectFactory()->getTypeDefinitionByBaseTypeId( |
|
519
|
1 |
|
$data[JSONConstants::JSON_TYPE_BASE_ID] ?? '', |
|
520
|
1 |
|
$data[JSONConstants::JSON_TYPE_ID] ?? '' |
|
521
|
1 |
|
); |
|
522
|
|
|
|
|
523
|
1 |
|
$data = $this->convertTypeDefinitionSpecificData($data, $typeDefinition); |
|
524
|
|
|
|
|
525
|
1 |
|
$data[JSONConstants::JSON_TYPE_TYPE_MUTABILITY] = $this->convertTypeMutability( |
|
526
|
1 |
|
$data[JSONConstants::JSON_TYPE_TYPE_MUTABILITY] ?? null |
|
527
|
1 |
|
); |
|
528
|
1 |
|
|
|
529
|
1 |
|
foreach ($data[JSONConstants::JSON_TYPE_PROPERTY_DEFINITIONS] ?? [] as $propertyDefinitionData) { |
|
|
|
|
|
|
530
|
1 |
|
if (is_array($propertyDefinitionData)) { |
|
531
|
1 |
|
$propertyDefinition = $this->convertPropertyDefinition($propertyDefinitionData); |
|
532
|
1 |
|
if ($propertyDefinition !== null) { |
|
533
|
1 |
|
$typeDefinition->addPropertyDefinition($propertyDefinition); |
|
534
|
1 |
|
} |
|
535
|
1 |
|
} |
|
536
|
|
|
} |
|
537
|
1 |
|
|
|
538
|
1 |
|
unset( |
|
539
|
1 |
|
$data[JSONConstants::JSON_TYPE_BASE_ID], |
|
540
|
|
|
$data[JSONConstants::JSON_TYPE_ID], |
|
541
|
1 |
|
$data[JSONConstants::JSON_TYPE_PROPERTY_DEFINITIONS] |
|
542
|
1 |
|
); |
|
543
|
|
|
|
|
544
|
1 |
|
$typeDefinition->populate( |
|
545
|
1 |
|
array_filter($data, function ($item) { return !empty($item); }), |
|
546
|
|
|
array_merge( |
|
547
|
|
|
array_combine(JSONConstants::getTypeKeys(), JSONConstants::getTypeKeys()), |
|
548
|
1 |
|
[ |
|
549
|
|
|
JSONConstants::JSON_TYPE_PARENT_ID => 'parentTypeId', |
|
550
|
1 |
|
JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES => 'allowedTargetTypeIds', |
|
551
|
|
|
JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES => 'allowedSourceTypeIds', |
|
552
|
|
|
] |
|
553
|
|
|
), |
|
554
|
|
|
true |
|
555
|
|
|
); |
|
556
|
|
|
|
|
557
|
|
|
$typeDefinition->setExtensions($this->convertExtension($data, JSONConstants::getTypeKeys())); |
|
558
|
|
|
|
|
559
|
|
|
return $typeDefinition; |
|
560
|
15 |
|
} |
|
561
|
|
|
|
|
562
|
15 |
|
/** |
|
563
|
1 |
|
* Convert specific type definition data so it can be populated to the type definition |
|
564
|
|
|
* |
|
565
|
|
|
* @param MutableTypeDefinitionInterface $typeDefinition The type definition to set the data to |
|
566
|
14 |
|
* @param array $data The data that contains the values that should be applied to the object |
|
567
|
1 |
|
* @return MutableTypeDefinitionInterface The type definition with the specific data applied |
|
568
|
|
|
*/ |
|
569
|
13 |
|
private function convertTypeDefinitionSpecificData(array $data, MutableTypeDefinitionInterface $typeDefinition) |
|
570
|
13 |
|
{ |
|
571
|
12 |
|
if ($typeDefinition instanceof MutableDocumentTypeDefinitionInterface) { |
|
572
|
12 |
|
if (!empty($data[JSONConstants::JSON_TYPE_CONTENTSTREAM_ALLOWED])) { |
|
573
|
12 |
|
$data[JSONConstants::JSON_TYPE_CONTENTSTREAM_ALLOWED] = ContentStreamAllowed::cast( |
|
574
|
|
|
$data[JSONConstants::JSON_TYPE_CONTENTSTREAM_ALLOWED] |
|
575
|
13 |
|
); |
|
576
|
13 |
|
} |
|
577
|
13 |
|
} elseif ($typeDefinition instanceof MutableRelationshipTypeDefinitionInterface) { |
|
578
|
13 |
|
|
|
579
|
|
|
$data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] = array_map( |
|
580
|
12 |
|
'strval', |
|
581
|
|
|
array_filter( |
|
582
|
12 |
|
$data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] ?? [], |
|
583
|
2 |
|
function ($item) { return !empty($item); } |
|
584
|
2 |
|
) |
|
585
|
2 |
|
); |
|
586
|
2 |
|
$data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] = array_map( |
|
587
|
|
|
'strval', |
|
588
|
|
|
array_filter( |
|
589
|
2 |
|
$data[JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES] ?? [], |
|
590
|
|
|
function ($item) { return !empty($item); } |
|
591
|
12 |
|
) |
|
592
|
12 |
|
); |
|
593
|
12 |
|
$data[JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES] = array_map( |
|
594
|
2 |
|
'strval', |
|
595
|
2 |
|
array_filter( |
|
596
|
2 |
|
$data[JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES] ?? [], |
|
597
|
2 |
|
function ($item) { return !empty($item); } |
|
598
|
|
|
) |
|
599
|
|
|
); |
|
600
|
2 |
|
|
|
601
|
2 |
|
} |
|
602
|
2 |
|
|
|
603
|
12 |
|
return $data; |
|
604
|
|
|
} |
|
605
|
12 |
|
|
|
606
|
12 |
|
/** |
|
607
|
12 |
|
* Convert an array to a type mutability object |
|
608
|
12 |
|
* |
|
609
|
|
|
* @param array|null $data The data that should be populated to the object |
|
610
|
12 |
|
* @return TypeMutability|null Returns the type mutability object or <code>null</code> if empty array is given |
|
611
|
12 |
|
*/ |
|
612
|
12 |
View Code Duplication |
public function convertTypeMutability(array $data = null) |
|
613
|
|
|
{ |
|
614
|
12 |
|
if (empty($data)) { |
|
615
|
|
|
return null; |
|
616
|
12 |
|
} |
|
617
|
|
|
$typeMutability = new TypeMutability(); |
|
618
|
12 |
|
$typeMutability->populate( |
|
619
|
|
|
$data, |
|
620
|
12 |
|
array_combine( |
|
621
|
|
|
JSONConstants::getTypeTypeMutabilityKeys(), |
|
622
|
|
|
array_map( |
|
623
|
|
|
function ($key) { |
|
624
|
|
|
// add a prefix "can" to all keys as this are the property names |
|
625
|
|
|
return 'can' . ucfirst($key); |
|
626
|
|
|
}, |
|
627
|
|
|
JSONConstants::getTypeTypeMutabilityKeys() |
|
628
|
|
|
) |
|
629
|
|
|
), |
|
630
|
|
|
true |
|
631
|
|
|
); |
|
632
|
|
|
|
|
633
|
|
|
$typeMutability->setExtensions( |
|
634
|
|
|
$this->convertExtension($data, JSONConstants::getTypeTypeMutabilityKeys()) |
|
635
|
|
|
); |
|
636
|
|
|
|
|
637
|
|
|
return $typeMutability; |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
/** |
|
641
|
|
|
* @param array|null $data |
|
642
|
|
|
* @return PropertyDefinitionInterface|null |
|
643
|
|
|
*/ |
|
644
|
|
|
public function convertPropertyDefinition(array $data = null) |
|
645
|
|
|
{ |
|
646
|
|
|
if (empty($data)) { |
|
647
|
|
|
return null; |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
$data = $this->preparePropertyDefinitionData($data); |
|
651
|
|
|
|
|
652
|
|
|
$propertyDefinition = $this->getPropertyDefinitionByType( |
|
653
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE], |
|
654
|
|
|
$data |
|
655
|
|
|
); |
|
656
|
|
|
|
|
657
|
|
|
// remove the id property as it has been already set to the property definition. |
|
658
|
|
|
unset($data[JSONConstants::JSON_PROPERTY_TYPE_ID]); |
|
659
|
|
|
|
|
660
|
|
|
// TODO |
|
661
|
|
|
// $propertyDefinition->setChoices( |
|
662
|
|
|
// $this->convertChoicesString($data[JSONConstants::JSON_PROPERTY_TYPE_CHOICE]) // TODO |
|
663
|
|
|
// ); |
|
664
|
|
|
// |
|
665
|
|
|
// // default value |
|
666
|
|
|
// Object defaultValue = json.get(JSON_PROPERTY_TYPE_DEAULT_VALUE); |
|
667
|
|
|
// if (defaultValue != null) { |
|
668
|
|
|
// if (defaultValue instanceof List) { |
|
669
|
|
|
// List values = new ArrayList(); |
|
670
|
|
|
// for (Object value : (List) defaultValue) { |
|
671
|
|
|
// values.add(getCMISValue(value, propertyType)); |
|
672
|
|
|
// } |
|
673
|
|
|
// result.setDefaultValue(values); |
|
674
|
|
|
// } else { |
|
675
|
|
|
// result.setDefaultValue((List) Collections.singletonList(getCMISValue(defaultValue, propertyType))); |
|
676
|
|
|
// } |
|
677
|
|
|
// } |
|
678
|
|
|
|
|
679
|
|
|
$propertyDefinition->populate( |
|
680
|
|
|
$data, |
|
681
|
|
|
[JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION => 'dateTimeResolution'] |
|
682
|
|
|
); |
|
683
|
|
|
$propertyDefinition->setExtensions($this->convertExtension($data, JSONConstants::getPropertyTypeKeys())); |
|
684
|
|
|
|
|
685
|
|
|
return $propertyDefinition; |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
|
/** |
|
689
|
|
|
* Cast data values to the expected type |
|
690
|
|
|
* |
|
691
|
|
|
* @param array $data |
|
692
|
|
|
* @return array |
|
693
|
|
|
*/ |
|
694
|
|
|
protected function preparePropertyDefinitionData(array $data) |
|
695
|
|
|
{ |
|
696
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE] = PropertyType::cast( |
|
697
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_PROPERTY_TYPE] |
|
698
|
|
|
); |
|
699
|
|
|
|
|
700
|
|
View Code Duplication |
if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_DEAULT_VALUE])) { |
|
701
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_DEAULT_VALUE] |
|
702
|
|
|
= (array) $data[JSONConstants::JSON_PROPERTY_TYPE_DEAULT_VALUE]; |
|
703
|
|
|
} |
|
704
|
|
|
|
|
705
|
|
|
if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION])) { |
|
706
|
9 |
|
$data[JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION] = DateTimeResolution::cast( |
|
707
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_RESOLUTION] |
|
708
|
9 |
|
); |
|
709
|
1 |
|
} |
|
710
|
|
|
|
|
711
|
|
|
if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_PRECISION])) { |
|
712
|
8 |
|
$data[JSONConstants::JSON_PROPERTY_TYPE_PRECISION] = DecimalPrecision::cast( |
|
713
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_PRECISION] |
|
714
|
8 |
|
); |
|
715
|
8 |
|
} |
|
716
|
|
|
|
|
717
|
8 |
|
if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_CARDINALITY])) { |
|
718
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_CARDINALITY] = Cardinality::cast( |
|
719
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_CARDINALITY] |
|
720
|
8 |
|
); |
|
721
|
|
|
} |
|
722
|
|
|
|
|
723
|
|
View Code Duplication |
if (isset($data[JSONConstants::JSON_PROPERTY_TYPE_UPDATABILITY])) { |
|
724
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_UPDATABILITY] = Updatability::cast( |
|
725
|
|
|
$data[JSONConstants::JSON_PROPERTY_TYPE_UPDATABILITY] |
|
726
|
|
|
); |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
return $data; |
|
730
|
|
|
} |
|
731
|
|
|
|
|
732
|
|
|
/** |
|
733
|
|
|
* @param PropertyType $propertyType |
|
734
|
|
|
* @param array $data |
|
735
|
|
|
* @return PropertyBooleanDefinition|PropertyDateTimeDefinition|PropertyDecimalDefinition|PropertyHtmlDefinition|PropertyIdDefinition|PropertyIntegerDefinition|PropertyStringDefinition |
|
736
|
|
|
*/ |
|
737
|
|
|
protected function getPropertyDefinitionByType(PropertyType $propertyType, array $data = []) |
|
738
|
|
|
{ |
|
739
|
|
|
$id = null; |
|
740
|
|
|
if (!empty($data[JSONConstants::JSON_PROPERTY_TYPE_ID])) { |
|
741
|
8 |
|
$id = $data[JSONConstants::JSON_PROPERTY_TYPE_ID]; |
|
742
|
8 |
|
} |
|
743
|
8 |
|
|
|
744
|
8 |
|
if ($propertyType->equals(PropertyType::STRING)) { |
|
745
|
8 |
|
$propertyDefinition = new PropertyStringDefinition($id); |
|
746
|
|
|
} elseif ($propertyType->equals(PropertyType::ID)) { |
|
747
|
8 |
|
$propertyDefinition = new PropertyIdDefinition($id); |
|
748
|
|
|
} elseif ($propertyType->equals(PropertyType::BOOLEAN)) { |
|
749
|
|
|
$propertyDefinition = new PropertyBooleanDefinition($id); |
|
750
|
|
|
} elseif ($propertyType->equals(PropertyType::INTEGER)) { |
|
751
|
|
|
$propertyDefinition = new PropertyIntegerDefinition($id); |
|
752
|
|
|
} elseif ($propertyType->equals(PropertyType::DATETIME)) { |
|
753
|
|
|
$propertyDefinition = new PropertyDateTimeDefinition($id); |
|
754
|
|
|
} elseif ($propertyType->equals(PropertyType::DECIMAL)) { |
|
755
|
|
|
$propertyDefinition = new PropertyDecimalDefinition($id); |
|
756
|
9 |
|
} elseif ($propertyType->equals(PropertyType::HTML)) { |
|
757
|
|
|
$propertyDefinition = new PropertyHtmlDefinition($id); |
|
758
|
9 |
|
} elseif ($propertyType->equals(PropertyType::URI)) { |
|
759
|
9 |
|
$propertyDefinition = new PropertyUriDefinition($id); |
|
760
|
9 |
|
} else { |
|
761
|
|
|
// @codeCoverageIgnoreStart |
|
762
|
9 |
|
// this could only happen if a new property type is added to the enumeration and not implemented here. |
|
763
|
1 |
|
throw new CmisInvalidArgumentException( |
|
764
|
1 |
|
sprintf('The given property definition "%s" could not be converted.', $propertyType) |
|
765
|
1 |
|
); |
|
766
|
|
|
// @codeCoverageIgnoreEnd |
|
767
|
9 |
|
} |
|
768
|
2 |
|
|
|
769
|
2 |
|
$propertyDefinition->setPropertyType($propertyType); |
|
770
|
2 |
|
|
|
771
|
2 |
|
return $propertyDefinition; |
|
772
|
|
|
} |
|
773
|
9 |
|
|
|
774
|
2 |
|
/** |
|
775
|
2 |
|
* Converts an object. |
|
776
|
2 |
|
* |
|
777
|
2 |
|
* @param array|null $data |
|
778
|
|
|
* @return null|ObjectData |
|
779
|
9 |
|
*/ |
|
780
|
9 |
|
public function convertObject(array $data = null) |
|
781
|
9 |
|
{ |
|
782
|
9 |
|
if (empty($data)) { |
|
783
|
9 |
|
return null; |
|
784
|
|
|
} |
|
785
|
9 |
|
|
|
786
|
9 |
|
$object = new ObjectData(); |
|
787
|
9 |
|
$acl = $this->convertAcl( |
|
788
|
9 |
|
$data[JSONConstants::JSON_OBJECT_ACL] ?? [], |
|
789
|
9 |
|
(boolean) $data[JSONConstants::JSON_OBJECT_EXACT_ACL] ?? false |
|
790
|
|
|
); |
|
791
|
9 |
|
if ($acl !== null) { |
|
792
|
|
|
$object->setAcl($acl); |
|
793
|
|
|
} |
|
794
|
|
|
|
|
795
|
|
|
$allowableActions = $this->convertAllowableActions($data[JSONConstants::JSON_OBJECT_ALLOWABLE_ACTIONS] ?? []); |
|
796
|
|
|
if ($allowableActions !== null) { |
|
797
|
|
|
$object->setAllowableActions($allowableActions); |
|
798
|
|
|
} |
|
799
|
8 |
|
|
|
800
|
|
|
if (isset($data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]) |
|
801
|
8 |
|
&& is_array($data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]) |
|
802
|
8 |
|
) { |
|
803
|
8 |
|
$changeEventInfoData = $data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]; |
|
804
|
8 |
|
$changeEventInfo = new ChangeEventInfo(); |
|
805
|
|
|
$changeEventInfo->setChangeTime( |
|
806
|
8 |
|
$this->convertDateTimeValue($changeEventInfoData[JSONConstants::JSON_CHANGE_EVENT_TIME]) |
|
807
|
1 |
|
); |
|
808
|
8 |
|
$changeEventInfo->setChangeType( |
|
809
|
1 |
|
ChangeType::cast($changeEventInfoData[JSONConstants::JSON_CHANGE_EVENT_TYPE]) |
|
810
|
7 |
|
); |
|
811
|
1 |
|
|
|
812
|
6 |
|
$changeEventInfo->setExtensions( |
|
813
|
1 |
|
$this->convertExtension($changeEventInfoData, JSONConstants::getChangeEventKeys()) |
|
814
|
5 |
|
); |
|
815
|
1 |
|
|
|
816
|
4 |
|
$object->setChangeEventInfo($changeEventInfo); |
|
817
|
1 |
|
} |
|
818
|
3 |
|
|
|
819
|
1 |
|
$object->setIsExactAcl((boolean) $data[JSONConstants::JSON_OBJECT_EXACT_ACL] ?? false); |
|
820
|
2 |
|
$object->setPolicyIds($this->convertPolicyIdList($data[JSONConstants::JSON_OBJECT_POLICY_IDS] ?? null)); |
|
821
|
1 |
|
|
|
822
|
1 |
|
/** |
|
823
|
|
|
* A client MAY add the query parameter succinct (HTTP GET) or the control succinct (HTTP POST) with the |
|
824
|
|
|
* value <code>true</code> to a request. If this is set, the repository MUST return properties in a succinct |
|
825
|
|
|
* format. That is, whenever the repository renders an object or a query result, it MUST populate the |
|
826
|
|
|
* succinctProperties value and MUST NOT populate the properties value. |
|
827
|
|
|
* |
|
828
|
|
|
* @see http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html#x1-552027r554 |
|
829
|
|
|
*/ |
|
830
|
|
|
if (isset($data[JSONConstants::JSON_OBJECT_SUCCINCT_PROPERTIES])) { |
|
831
|
8 |
|
$properties = $this->convertSuccinctProperties( |
|
832
|
|
|
$data[JSONConstants::JSON_OBJECT_SUCCINCT_PROPERTIES] ?? [], |
|
833
|
8 |
|
$data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION] ?? []); |
|
834
|
|
|
} else { |
|
835
|
|
|
$properties = $this->convertProperties( |
|
836
|
|
|
$data[JSONConstants::JSON_OBJECT_PROPERTIES] ?? [], |
|
837
|
|
|
(array) $data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION] ?? [] |
|
838
|
|
|
); |
|
839
|
|
|
} |
|
840
|
|
|
|
|
841
|
|
|
$object->setProperties($properties ?? []); |
|
|
|
|
|
|
842
|
2 |
|
$object->setRelationships($this->convertObjects($data[JSONConstants::JSON_OBJECT_RELATIONSHIPS] ?? null)); |
|
843
|
|
|
$object->setRenditions($this->convertRenditions($data[JSONConstants::JSON_OBJECT_RENDITIONS] ?? [])); |
|
844
|
2 |
|
$object->setExtensions($this->convertExtension($data, JSONConstants::getObjectKeys())); |
|
845
|
1 |
|
|
|
846
|
|
|
return $object; |
|
847
|
|
|
} |
|
848
|
1 |
|
|
|
849
|
1 |
|
/** |
|
850
|
1 |
|
* @param array|null $data |
|
851
|
1 |
|
* @return ObjectDataInterface[] |
|
852
|
1 |
|
*/ |
|
853
|
1 |
View Code Duplication |
public function convertObjects(array $data = null) |
|
|
|
|
|
|
854
|
1 |
|
{ |
|
855
|
1 |
|
return array_filter( |
|
856
|
1 |
|
array_map( |
|
857
|
1 |
|
[$this, 'convertObject'], |
|
858
|
1 |
|
array_filter( |
|
859
|
1 |
|
(array) $data, |
|
860
|
|
|
'is_array' |
|
861
|
1 |
|
) |
|
862
|
1 |
|
), |
|
863
|
1 |
|
function ($item) { |
|
864
|
1 |
|
// @TODO once a logger is available we should log an INFO message if the object could not be converted |
|
865
|
1 |
|
return !empty($item); |
|
866
|
1 |
|
} |
|
867
|
|
|
); |
|
868
|
1 |
|
} |
|
869
|
1 |
|
|
|
870
|
1 |
|
/** |
|
871
|
1 |
|
* @param array|null $data |
|
872
|
1 |
|
* @param array $extensions |
|
873
|
1 |
|
* @return null|Properties |
|
874
|
1 |
|
* @throws CmisRuntimeException |
|
875
|
1 |
|
*/ |
|
876
|
1 |
|
public function convertProperties(array $data = null, $extensions = []) |
|
877
|
1 |
|
{ |
|
878
|
1 |
|
if (empty($data)) { |
|
879
|
|
|
return null; |
|
880
|
1 |
|
} |
|
881
|
1 |
|
$properties = new Properties(); |
|
882
|
1 |
|
|
|
883
|
|
|
foreach ($data as $propertyData) { |
|
884
|
1 |
|
$id = $propertyData[JSONConstants::JSON_PROPERTY_ID] ?? null; |
|
885
|
1 |
|
$queryName = $propertyData[JSONConstants::JSON_PROPERTY_QUERYNAME] ?? null; |
|
886
|
|
|
|
|
887
|
1 |
|
// A Property must always have an ID except if it used in a query result. |
|
888
|
1 |
|
// In a query result a Property should have an ID and must have a query name. |
|
889
|
1 |
|
if ($id === null && $queryName === null) { |
|
890
|
1 |
|
throw new CmisRuntimeException('Invalid property! Neither a property ID nor a query name is provided!'); |
|
891
|
1 |
|
} |
|
892
|
1 |
|
|
|
893
|
|
|
try { |
|
894
|
|
|
$propertyType = PropertyType::cast($propertyData[JSONConstants::JSON_PROPERTY_DATATYPE]); |
|
895
|
|
|
} catch (InvalidEnumerationValueException $exception) { |
|
896
|
|
|
throw new CmisRuntimeException( |
|
897
|
|
|
sprintf('Unknown property type "%s"!', $propertyData[JSONConstants::JSON_PROPERTY_DATATYPE]) |
|
898
|
|
|
); |
|
899
|
|
|
} |
|
900
|
|
|
|
|
901
|
|
|
// get property keys without JSON-response-specific cardinality properties |
|
902
|
1 |
|
$jsonPropertyKeys = JSONConstants::getPropertyKeys(); |
|
903
|
1 |
|
$propertyKeys = array_values( |
|
904
|
1 |
|
array_diff( |
|
905
|
|
|
$jsonPropertyKeys, |
|
906
|
|
|
[ |
|
907
|
|
|
// remove the cardinality property here as this is not a property of a property but only |
|
908
|
|
|
// required for the other way when converting the property to the JSON object for the |
|
909
|
|
|
// browser binding. |
|
910
|
|
|
JSONConstants::JSON_PROPERTY_CARDINALITY, |
|
911
|
1 |
|
JSONConstants::JSON_PROPERTY_VALUE, |
|
912
|
1 |
|
JSONConstants::JSON_PROPERTY_ID, |
|
913
|
1 |
|
JSONConstants::JSON_PROPERTY_DATATYPE |
|
914
|
1 |
|
] |
|
915
|
1 |
|
) |
|
916
|
1 |
|
); |
|
917
|
1 |
|
|
|
918
|
1 |
|
$property = $this->getPropertyByPropertyType( |
|
919
|
1 |
|
$propertyType, |
|
920
|
1 |
|
$id, |
|
921
|
1 |
|
(array) $propertyData[JSONConstants::JSON_PROPERTY_VALUE] ?? [] |
|
922
|
1 |
|
); |
|
923
|
|
|
$property->populate( |
|
924
|
1 |
|
$propertyData, |
|
925
|
1 |
|
$propertyKeys, |
|
926
|
1 |
|
true |
|
927
|
|
|
); |
|
928
|
|
|
$property->setExtensions($this->convertExtension($propertyData, $jsonPropertyKeys)); |
|
929
|
|
|
|
|
930
|
|
|
$properties->addProperty($property); |
|
931
|
|
|
} |
|
932
|
|
|
|
|
933
|
1 |
|
if (!empty($extensions)) { |
|
934
|
1 |
|
$properties->setExtensions($this->convertExtension($extensions)); |
|
935
|
1 |
|
} |
|
936
|
1 |
|
|
|
937
|
1 |
|
return $properties; |
|
938
|
|
|
} |
|
939
|
1 |
|
|
|
940
|
|
|
/** |
|
941
|
1 |
|
* @param PropertyType $propertyType |
|
942
|
|
|
* @param string $id |
|
943
|
|
|
* @param array $propertyValues |
|
944
|
|
|
* @return PropertyBoolean|PropertyDateTime|PropertyDecimal|PropertyHtml|PropertyId|PropertyInteger|PropertyString |
|
945
|
|
|
*/ |
|
946
|
|
|
protected function getPropertyByPropertyType(PropertyType $propertyType, $id, array $propertyValues) |
|
947
|
|
|
{ |
|
948
|
2 |
|
if ($propertyType->equals(PropertyType::cast(PropertyType::STRING))) { |
|
949
|
|
|
$property = new PropertyString($id, $this->convertStringValues($propertyValues)); |
|
950
|
2 |
|
} elseif ($propertyType->equals(PropertyType::cast(PropertyType::ID))) { |
|
951
|
|
|
$property = new PropertyId($id, $this->convertStringValues($propertyValues)); |
|
952
|
2 |
|
} elseif ($propertyType->equals(PropertyType::cast(PropertyType::BOOLEAN))) { |
|
953
|
1 |
|
$property = new PropertyBoolean($id, $this->convertBooleanValues($propertyValues)); |
|
954
|
|
|
} elseif ($propertyType->equals(PropertyType::cast(PropertyType::INTEGER))) { |
|
955
|
|
|
$property = new PropertyInteger($id, $this->convertIntegerValues($propertyValues)); |
|
956
|
1 |
|
} elseif ($propertyType->equals(PropertyType::cast(PropertyType::DATETIME))) { |
|
957
|
1 |
|
$property = new PropertyDateTime($id, $this->convertDateTimeValues($propertyValues)); |
|
958
|
1 |
|
} elseif ($propertyType->equals(PropertyType::cast(PropertyType::DECIMAL))) { |
|
959
|
|
|
$property = new PropertyDecimal($id, $this->convertDecimalValues($propertyValues)); |
|
960
|
1 |
|
} elseif ($propertyType->equals(PropertyType::cast(PropertyType::HTML))) { |
|
961
|
|
|
$property = new PropertyHtml($id, $this->convertStringValues($propertyValues)); |
|
962
|
|
|
} elseif ($propertyType->equals(PropertyType::cast(PropertyType::URI))) { |
|
963
|
1 |
|
$property = new PropertyUri($id, $this->convertStringValues($propertyValues)); |
|
964
|
1 |
|
} else { |
|
965
|
1 |
|
// this could only happen if a new property type is added to the enumeration and not implemented here. |
|
966
|
1 |
|
throw new CmisInvalidArgumentException( |
|
967
|
|
|
sprintf('The given property type "%s" could not be converted.', $propertyType) |
|
968
|
1 |
|
); |
|
969
|
|
|
} |
|
970
|
|
|
|
|
971
|
|
|
return $property; |
|
972
|
|
|
} |
|
973
|
|
|
|
|
974
|
|
|
/** |
|
975
|
|
|
* TODO Add description |
|
976
|
|
|
* |
|
977
|
4 |
|
* @param array|null $data |
|
978
|
|
|
* @param array $extensions |
|
979
|
4 |
|
* @return PropertiesInterface |
|
980
|
1 |
|
* @throws \Exception |
|
981
|
|
|
*/ |
|
982
|
3 |
|
public function convertSuccinctProperties(array $data = null, $extensions = []) |
|
983
|
|
|
{ |
|
984
|
3 |
|
throw new \Exception('Succinct properties are currently not supported.'); |
|
985
|
3 |
|
// TODO IMPLEMENT SUCCINCT PROPERTY SUPPORT |
|
986
|
3 |
|
// if (empty($data)) { |
|
987
|
3 |
|
// return null; |
|
988
|
3 |
|
// } |
|
989
|
|
|
// if (isset($data[PropertyIds::SECONDARY_OBJECT_TYPE_IDS]) |
|
990
|
|
|
// && is_array($data[PropertyIds::SECONDARY_OBJECT_TYPE_IDS]) |
|
991
|
|
|
// ) { |
|
992
|
3 |
|
// $secondaryTypeIds = $data[PropertyIds::SECONDARY_OBJECT_TYPE_IDS]; |
|
993
|
1 |
|
// $secondaryTypeDefinitions = array(); |
|
994
|
|
|
// foreach($secondaryTypeIds as $secondaryTypeId) { |
|
995
|
|
|
// if ((string) $secondaryTypeId !== "") { |
|
996
|
|
|
// $secondaryTypeDefinitions[] = |
|
997
|
2 |
|
// } |
|
998
|
2 |
|
// } |
|
999
|
1 |
|
// } |
|
1000
|
1 |
|
// |
|
1001
|
1 |
|
// $properties = array(); |
|
1002
|
|
|
// |
|
1003
|
|
|
// foreach ($data as $propertyId => $propertyData) { |
|
1004
|
1 |
|
// ... |
|
1005
|
|
|
// } |
|
1006
|
1 |
|
// |
|
1007
|
1 |
|
// return $properties; |
|
1008
|
1 |
|
} |
|
1009
|
1 |
|
|
|
1010
|
|
|
/** |
|
1011
|
|
|
* Convert given input data to a RenditionData object |
|
1012
|
|
|
* |
|
1013
|
1 |
|
* @param array|null $data |
|
1014
|
1 |
|
* @return null|RenditionData |
|
1015
|
1 |
|
*/ |
|
1016
|
1 |
|
public function convertRendition(array $data = null) |
|
1017
|
|
|
{ |
|
1018
|
|
|
if (empty($data)) { |
|
1019
|
|
|
return null; |
|
1020
|
|
|
} |
|
1021
|
1 |
|
$rendition = new RenditionData(); |
|
1022
|
1 |
|
|
|
1023
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_HEIGHT])) { |
|
1024
|
|
|
$rendition->setHeight((integer) $data[JSONConstants::JSON_RENDITION_HEIGHT]); |
|
1025
|
1 |
|
} |
|
1026
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_KIND])) { |
|
1027
|
1 |
|
$rendition->setKind((string) $data[JSONConstants::JSON_RENDITION_KIND]); |
|
1028
|
|
|
} |
|
1029
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_LENGTH])) { |
|
1030
|
1 |
|
$rendition->setLength((integer) $data[JSONConstants::JSON_RENDITION_LENGTH]); |
|
1031
|
1 |
|
} |
|
1032
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_MIMETYPE])) { |
|
1033
|
|
|
$rendition->setMimeType((string) $data[JSONConstants::JSON_RENDITION_MIMETYPE]); |
|
1034
|
1 |
|
} |
|
1035
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_DOCUMENT_ID])) { |
|
1036
|
|
|
$rendition->setRenditionDocumentId((string) $data[JSONConstants::JSON_RENDITION_DOCUMENT_ID]); |
|
1037
|
1 |
|
} |
|
1038
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_STREAM_ID])) { |
|
1039
|
|
|
$rendition->setStreamId((string) $data[JSONConstants::JSON_RENDITION_STREAM_ID]); |
|
1040
|
1 |
|
} |
|
1041
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_TITLE])) { |
|
1042
|
1 |
|
$rendition->setTitle((string) $data[JSONConstants::JSON_RENDITION_TITLE]); |
|
1043
|
|
|
} |
|
1044
|
1 |
|
if (isset($data[JSONConstants::JSON_RENDITION_WIDTH])) { |
|
1045
|
|
|
$rendition->setWidth((integer) $data[JSONConstants::JSON_RENDITION_WIDTH]); |
|
1046
|
|
|
} |
|
1047
|
|
|
|
|
1048
|
|
|
$rendition->setExtensions($this->convertExtension($data, JSONConstants::getRenditionKeys())); |
|
1049
|
|
|
|
|
1050
|
|
|
return $rendition; |
|
1051
|
|
|
} |
|
1052
|
|
|
|
|
1053
|
1 |
|
/** |
|
1054
|
|
|
* Convert given input data to a list of RenditionData objects |
|
1055
|
1 |
|
* |
|
1056
|
1 |
|
* @param array|null $data |
|
1057
|
1 |
|
* @return RenditionData[] |
|
1058
|
1 |
|
*/ |
|
1059
|
1 |
View Code Duplication |
public function convertRenditions(array $data = null) |
|
|
|
|
|
|
1060
|
1 |
|
{ |
|
1061
|
1 |
|
return array_filter( |
|
1062
|
1 |
|
array_map( |
|
1063
|
1 |
|
[$this, 'convertRendition'], |
|
1064
|
1 |
|
array_filter( |
|
1065
|
1 |
|
$data, |
|
1066
|
1 |
|
'is_array' |
|
1067
|
1 |
|
) |
|
1068
|
1 |
|
), |
|
1069
|
1 |
|
function ($item) { |
|
1070
|
1 |
|
// @TODO once a logger is available we should log an INFO message if the rendition could not be converted |
|
1071
|
1 |
|
return !empty($item); |
|
1072
|
|
|
} |
|
1073
|
|
|
); |
|
1074
|
|
|
} |
|
1075
|
|
|
|
|
1076
|
|
|
/** |
|
1077
|
|
|
* Convert given input data to an Extension object |
|
1078
|
1 |
|
* |
|
1079
|
|
|
* @param array|null $data |
|
1080
|
|
|
* @param string[] $cmisKeys |
|
1081
|
|
|
* @return CmisExtensionElement[] |
|
1082
|
|
|
*/ |
|
1083
|
|
|
public function convertExtension(array $data = null, array $cmisKeys = []) |
|
1084
|
|
|
{ |
|
1085
|
|
|
$extensions = []; |
|
1086
|
|
|
|
|
1087
|
|
|
foreach (array_diff_key((array) $data, array_flip($cmisKeys)) as $key => $value) { |
|
1088
|
|
|
|
|
1089
|
|
|
if (!is_array($value)) { |
|
1090
|
|
|
$value = (empty($value)) ? null : (string) $value; |
|
1091
|
|
|
$extensions[] = new CmisExtensionElement(null, $key, [], $value); |
|
1092
|
|
|
} else { |
|
1093
|
|
|
$extension = $this->convertExtension($value, $cmisKeys); |
|
1094
|
|
|
|
|
1095
|
|
|
if (!empty($extension)) { |
|
1096
|
|
|
$extensions[] = new CmisExtensionElement( |
|
1097
|
|
|
null, |
|
1098
|
|
|
$key, |
|
1099
|
|
|
[], |
|
1100
|
|
|
null, |
|
1101
|
|
|
$extension |
|
1102
|
|
|
); |
|
1103
|
|
|
} |
|
1104
|
|
|
} |
|
1105
|
|
|
} |
|
1106
|
|
|
|
|
1107
|
|
|
return $extensions; |
|
1108
|
|
|
} |
|
1109
|
|
|
|
|
1110
|
|
|
/** |
|
1111
|
|
|
* Convert given input data to an ExtensionFeature object |
|
1112
|
|
|
* |
|
1113
|
|
|
* @param array|null $data |
|
1114
|
|
|
* @return ExtensionFeature[] |
|
1115
|
|
|
*/ |
|
1116
|
|
|
public function convertExtensionFeatures(array $data = null) |
|
1117
|
|
|
{ |
|
1118
|
|
|
$features = []; |
|
1119
|
|
|
$extendedFeatures = array_filter(array_filter((array) $data, 'is_array'), function ($item) { return !empty($item); }); |
|
1120
|
|
|
|
|
1121
|
|
|
foreach ($extendedFeatures as $extendedFeature) { |
|
1122
|
|
|
|
|
1123
|
3 |
|
$feature = new ExtensionFeature(); |
|
1124
|
|
|
$feature->setId((string) $extendedFeature[JSONConstants::JSON_FEATURE_ID]); |
|
1125
|
3 |
|
$feature->setUrl((string) $extendedFeature[JSONConstants::JSON_FEATURE_URL]); |
|
1126
|
1 |
|
$feature->setCommonName((string) $extendedFeature[JSONConstants::JSON_FEATURE_COMMON_NAME]); |
|
1127
|
|
|
$feature->setVersionLabel((string) $extendedFeature[JSONConstants::JSON_FEATURE_VERSION_LABEL]); |
|
1128
|
2 |
|
$feature->setDescription((string) $extendedFeature[JSONConstants::JSON_FEATURE_DESCRIPTION]); |
|
1129
|
|
|
|
|
1130
|
2 |
|
$featureData = []; |
|
1131
|
2 |
|
foreach ($extendedFeature[JSONConstants::JSON_FEATURE_DATA] ?? [] as $key => $value) { |
|
1132
|
2 |
|
$featureData[$key] = $value; |
|
1133
|
2 |
|
} |
|
1134
|
2 |
|
|
|
1135
|
2 |
|
$feature->setFeatureData($featureData); |
|
1136
|
2 |
|
|
|
1137
|
2 |
|
$feature->setExtensions($this->convertExtension($extendedFeature, JSONConstants::getFeatureKeys())); |
|
1138
|
2 |
|
|
|
1139
|
2 |
|
$features[] = $feature; |
|
1140
|
2 |
|
} |
|
1141
|
2 |
|
|
|
1142
|
2 |
|
return $features; |
|
1143
|
2 |
|
} |
|
1144
|
2 |
|
|
|
1145
|
2 |
|
/** |
|
1146
|
2 |
|
* Converts a list of policy ids. |
|
1147
|
2 |
|
* |
|
1148
|
2 |
|
* @param array|null $data |
|
1149
|
2 |
|
* @return PolicyIdList List of policy ids |
|
1150
|
2 |
|
*/ |
|
1151
|
2 |
View Code Duplication |
public function convertPolicyIdList(array $data = null) |
|
|
|
|
|
|
1152
|
2 |
|
{ |
|
1153
|
2 |
|
$policyIdsList = new PolicyIdList(); |
|
1154
|
|
|
$policyIdsList->setPolicyIds( |
|
1155
|
2 |
|
array_filter( |
|
1156
|
|
|
array_filter( |
|
1157
|
2 |
|
$data[JSONConstants::JSON_OBJECT_POLICY_IDS_IDS] ?? [], |
|
1158
|
|
|
'is_string' |
|
1159
|
|
|
), |
|
1160
|
|
|
function ($item) { return !empty($item); } |
|
1161
|
|
|
) |
|
1162
|
|
|
); |
|
1163
|
|
|
$policyIdsList->setExtensions($this->convertExtension($data, JSONConstants::getPolicyIdsKeys())); |
|
1164
|
|
|
|
|
1165
|
|
|
return $policyIdsList; |
|
1166
|
4 |
|
} |
|
1167
|
|
|
|
|
1168
|
4 |
|
/** |
|
1169
|
1 |
|
* Convert an acl object to a custom format |
|
1170
|
|
|
* |
|
1171
|
3 |
|
* @param AclInterface $acl |
|
1172
|
|
|
* @return mixed |
|
1173
|
3 |
|
*/ |
|
1174
|
3 |
|
public function convertFromAcl(AclInterface $acl) |
|
1175
|
3 |
|
{ |
|
1176
|
1 |
|
// TODO: Implement convertFromAcl() method. |
|
1177
|
1 |
|
} |
|
1178
|
|
|
|
|
1179
|
|
|
/** |
|
1180
|
3 |
|
* Convert an acl capabilities object to a custom format |
|
1181
|
1 |
|
* |
|
1182
|
1 |
|
* @param AclCapabilitiesInterface $aclCapabilities |
|
1183
|
3 |
|
* @return mixed |
|
1184
|
|
|
*/ |
|
1185
|
3 |
|
public function convertFromAclCapabilities(AclCapabilitiesInterface $aclCapabilities) |
|
1186
|
|
|
{ |
|
1187
|
|
|
// TODO: Implement convertFromAclCapabilities() method. |
|
1188
|
|
|
} |
|
1189
|
|
|
|
|
1190
|
|
|
/** |
|
1191
|
|
|
* Convert an allowable actions object to a custom format |
|
1192
|
|
|
* |
|
1193
|
|
|
* @param AllowableActionsInterface $allowableActions |
|
1194
|
|
|
* @return mixed |
|
1195
|
31 |
|
*/ |
|
1196
|
|
|
public function convertFromAllowableActions(AllowableActionsInterface $allowableActions) |
|
1197
|
31 |
|
{ |
|
1198
|
1 |
|
// TODO: Implement convertFromAllowableActions() method. |
|
1199
|
|
|
} |
|
1200
|
|
|
|
|
1201
|
30 |
|
/** |
|
1202
|
|
|
* Convert a repository info object to a custom format |
|
1203
|
30 |
|
* |
|
1204
|
30 |
|
* @param RepositoryInfoInterface $repositoryInfo |
|
1205
|
28 |
|
* @return mixed |
|
1206
|
|
|
*/ |
|
1207
|
|
|
public function convertFromRepositoryInfo(RepositoryInfoInterface $repositoryInfo) |
|
1208
|
11 |
|
{ |
|
1209
|
1 |
|
// TODO: Implement convertFromRepositoryInfo() method. |
|
1210
|
|
|
} |
|
1211
|
1 |
|
|
|
1212
|
1 |
|
/** |
|
1213
|
1 |
|
* Convert a repository capabilities object to a custom format |
|
1214
|
1 |
|
* |
|
1215
|
1 |
|
* @param RepositoryCapabilitiesInterface $repositoryCapabilities |
|
1216
|
1 |
|
* @return mixed |
|
1217
|
|
|
*/ |
|
1218
|
1 |
|
public function convertFromRepositoryCapabilities(RepositoryCapabilitiesInterface $repositoryCapabilities) |
|
1219
|
1 |
|
{ |
|
1220
|
1 |
|
// TODO: Implement convertFromRepositoryCapabilities() method. |
|
1221
|
11 |
|
} |
|
1222
|
11 |
|
|
|
1223
|
|
|
/** |
|
1224
|
30 |
|
* Convert a rendition data object to a custom format |
|
1225
|
|
|
* |
|
1226
|
30 |
|
* @param RenditionDataInterface $rendition |
|
1227
|
|
|
* @return mixed |
|
1228
|
|
|
*/ |
|
1229
|
|
|
public function convertFromRenditionData(RenditionDataInterface $rendition) |
|
1230
|
|
|
{ |
|
1231
|
|
|
// TODO: Implement convertFromRenditionData() method. |
|
1232
|
|
|
} |
|
1233
|
|
|
|
|
1234
|
|
|
/** |
|
1235
|
1 |
|
* Convert a object data object to a custom format |
|
1236
|
|
|
* |
|
1237
|
1 |
|
* @param ObjectDataInterface $objectData |
|
1238
|
|
|
* @return mixed |
|
1239
|
1 |
|
*/ |
|
1240
|
|
|
public function convertFromObjectData(ObjectDataInterface $objectData) |
|
1241
|
|
|
{ |
|
1242
|
|
|
// TODO: Implement convertFromObjectData() method. |
|
1243
|
1 |
|
} |
|
1244
|
1 |
|
|
|
1245
|
1 |
|
/** |
|
1246
|
|
|
* Convert a properties object to a custom format |
|
1247
|
|
|
* |
|
1248
|
1 |
|
* @param PropertiesInterface $properties |
|
1249
|
1 |
|
* @return mixed |
|
1250
|
1 |
|
*/ |
|
1251
|
1 |
|
public function convertFromProperties(PropertiesInterface $properties) |
|
1252
|
1 |
|
{ |
|
1253
|
1 |
|
// TODO: Implement convertFromProperties() method. |
|
1254
|
|
|
} |
|
1255
|
1 |
|
|
|
1256
|
1 |
|
/** |
|
1257
|
1 |
|
* Convert a property data object to a custom format |
|
1258
|
1 |
|
* |
|
1259
|
1 |
|
* @param PropertyDataInterface $propertyData |
|
1260
|
1 |
|
* @return mixed |
|
1261
|
1 |
|
*/ |
|
1262
|
|
|
public function convertFromPropertyData(PropertyDataInterface $propertyData) |
|
1263
|
1 |
|
{ |
|
1264
|
1 |
|
// TODO: Implement convertFromPropertyData() method. |
|
1265
|
|
|
} |
|
1266
|
1 |
|
|
|
1267
|
|
|
/** |
|
1268
|
1 |
|
* Convert a type definition object to a custom format |
|
1269
|
1 |
|
* |
|
1270
|
|
|
* @param TypeDefinitionInterface $typeDefinition |
|
1271
|
1 |
|
* @return string JSON representation of the type definition |
|
1272
|
|
|
*/ |
|
1273
|
|
|
public function convertFromTypeDefinition(TypeDefinitionInterface $typeDefinition) |
|
1274
|
|
|
{ |
|
1275
|
|
|
$propertyList = [ |
|
1276
|
|
|
'baseTypeId' => JSONConstants::JSON_TYPE_BASE_ID, |
|
1277
|
|
|
'parentTypeId' => JSONConstants::JSON_TYPE_PARENT_ID |
|
1278
|
|
|
]; |
|
1279
|
|
|
|
|
1280
|
1 |
|
if ($typeDefinition instanceof RelationshipTypeDefinitionInterface) { |
|
1281
|
|
|
$propertyList['allowedTargetTypeIds'] = JSONConstants::JSON_TYPE_ALLOWED_TARGET_TYPES; |
|
1282
|
1 |
|
$propertyList['allowedSourceTypeIds'] = JSONConstants::JSON_TYPE_ALLOWED_SOURCE_TYPES; |
|
1283
|
1 |
|
} |
|
1284
|
|
|
|
|
1285
|
1 |
|
$data = $typeDefinition->exportGettableProperties( |
|
1286
|
1 |
|
$propertyList |
|
1287
|
1 |
|
); |
|
1288
|
1 |
|
$data = $this->castArrayValuesToSimpleTypes($data); |
|
1289
|
1 |
|
|
|
1290
|
1 |
|
return json_encode($data, JSON_FORCE_OBJECT); |
|
1291
|
1 |
|
} |
|
1292
|
|
|
|
|
1293
|
1 |
|
/** |
|
1294
|
1 |
|
* Cast values of an array to simple types |
|
1295
|
|
|
* |
|
1296
|
1 |
|
* @param array $data |
|
1297
|
|
|
* @return array |
|
1298
|
|
|
*/ |
|
1299
|
|
|
protected function castArrayValuesToSimpleTypes(array $data) |
|
1300
|
|
|
{ |
|
1301
|
|
|
foreach ($data as $key => $item) { |
|
1302
|
|
|
if (is_array($item)) { |
|
1303
|
|
|
$data[$key] = $this->castArrayValuesToSimpleTypes($item); |
|
1304
|
|
|
} elseif (is_object($item)) { |
|
1305
|
|
|
$data[$key] = $this->convertObjectToSimpleType($item); |
|
1306
|
|
|
} |
|
1307
|
|
|
} |
|
1308
|
|
|
|
|
1309
|
|
|
return $data; |
|
1310
|
|
|
} |
|
1311
|
|
|
|
|
1312
|
|
|
/** |
|
1313
|
|
|
* Convert an object to a simple type representation |
|
1314
|
|
|
* |
|
1315
|
|
|
* @param mixed $data |
|
1316
|
|
|
* @return mixed |
|
1317
|
|
|
* @throws CmisRuntimeException Exception is thrown if no type converter could be found to convert the given data |
|
1318
|
|
|
* to a simple type |
|
1319
|
|
|
*/ |
|
1320
|
|
|
protected function convertObjectToSimpleType($data) |
|
1321
|
|
|
{ |
|
1322
|
|
|
/** @var null|TypeConverterInterface $converterClassName */ |
|
1323
|
|
|
$converterClassName = null; |
|
1324
|
|
|
if (class_exists($this->buildConverterClassName(get_class($data)))) { |
|
1325
|
|
|
$converterClassName = $this->buildConverterClassName(get_class($data)); |
|
1326
|
|
|
} else { |
|
1327
|
|
|
$classInterfaces = class_implements($data); |
|
1328
|
|
|
foreach ((array) $classInterfaces as $classInterface) { |
|
1329
|
|
|
if (class_exists($this->buildConverterClassName($classInterface))) { |
|
1330
|
|
|
$converterClassName = $this->buildConverterClassName($classInterface); |
|
1331
|
|
|
break; |
|
1332
|
|
|
} |
|
1333
|
|
|
} |
|
1334
|
|
|
if ($converterClassName === null) { |
|
1335
|
|
|
$classParents = class_parents($data); |
|
1336
|
|
|
foreach ((array) $classParents as $classParent) { |
|
1337
|
|
|
if (class_exists($this->buildConverterClassName($classParent))) { |
|
1338
|
|
|
$converterClassName = $this->buildConverterClassName($classParent); |
|
1339
|
|
|
break; |
|
1340
|
|
|
} |
|
1341
|
|
|
} |
|
1342
|
|
|
} |
|
1343
|
|
|
} |
|
1344
|
|
|
|
|
1345
|
|
|
if ($converterClassName === null) { |
|
1346
|
|
|
throw new CmisRuntimeException( |
|
1347
|
|
|
'Could not find a converter that converts "' . get_class($data) . '" to a simple type.' |
|
1348
|
|
|
); |
|
1349
|
|
|
} |
|
1350
|
|
|
|
|
1351
|
|
|
return $converterClassName::convertToSimpleType($data); |
|
1352
|
|
|
} |
|
1353
|
|
|
|
|
1354
|
|
|
/** |
|
1355
|
|
|
* Build a converter class name with namespace. |
|
1356
|
|
|
* |
|
1357
|
|
|
* The Dkd\PhpCmis namespace will be stripped. |
|
1358
|
|
|
* |
|
1359
|
|
|
* @param $className |
|
1360
|
|
|
* @return string |
|
1361
|
|
|
*/ |
|
1362
|
|
|
protected function buildConverterClassName($className) |
|
1363
|
|
|
{ |
|
1364
|
|
|
$converterClassName = '\\Dkd\\PhpCmis\\Converter\\Types\\'; |
|
1365
|
|
|
$converterClassName .= str_replace('Dkd\\PhpCmis\\', '', $className); |
|
1366
|
|
|
$converterClassName .= 'Converter'; |
|
1367
|
|
|
return $converterClassName; |
|
1368
|
|
|
} |
|
1369
|
|
|
|
|
1370
|
|
|
/** |
|
1371
|
|
|
* Convert a property definition object to a custom format |
|
1372
|
|
|
* |
|
1373
|
|
|
* @param PropertyDefinitionInterface $propertyDefinition |
|
1374
|
|
|
* @return mixed |
|
1375
|
|
|
*/ |
|
1376
|
|
|
public function convertFromPropertyDefinition(PropertyDefinitionInterface $propertyDefinition) |
|
1377
|
|
|
{ |
|
1378
|
|
|
// TODO: Implement convertFromPropertyDefinition() method. |
|
1379
|
|
|
} |
|
1380
|
|
|
|
|
1381
|
|
|
/** |
|
1382
|
|
|
* Convert a type definition list object to a custom format |
|
1383
|
|
|
* |
|
1384
|
|
|
* @param TypeDefinitionListInterface $typeDefinitionList |
|
1385
|
|
|
* @return mixed |
|
1386
|
|
|
*/ |
|
1387
|
|
|
public function convertFromTypeDefinitionList(TypeDefinitionListInterface $typeDefinitionList) |
|
1388
|
|
|
{ |
|
1389
|
|
|
// TODO: Implement convertFromTypeDefinitionList() method. |
|
1390
|
|
|
} |
|
1391
|
|
|
|
|
1392
|
|
|
/** |
|
1393
|
|
|
* Convert a type definition container object to a custom format |
|
1394
|
|
|
* |
|
1395
|
|
|
* @param TypeDefinitionContainerInterface $typeDefinitionContainer |
|
1396
|
|
|
* @return mixed |
|
1397
|
|
|
*/ |
|
1398
|
|
|
public function convertFromTypeDefinitionContainer(TypeDefinitionContainerInterface $typeDefinitionContainer) |
|
1399
|
|
|
{ |
|
1400
|
|
|
// TODO: Implement convertFromTypeDefinitionContainer() method. |
|
1401
|
|
|
} |
|
1402
|
|
|
|
|
1403
|
|
|
/** |
|
1404
|
|
|
* Convert a object list object to a custom format |
|
1405
|
|
|
* |
|
1406
|
|
|
* @param ObjectListInterface $list |
|
1407
|
|
|
* @return mixed |
|
1408
|
|
|
*/ |
|
1409
|
|
|
public function convertFromObjectList(ObjectListInterface $list) |
|
1410
|
|
|
{ |
|
1411
|
|
|
// TODO: Implement convertFromObjectList() method. |
|
1412
|
|
|
} |
|
1413
|
|
|
|
|
1414
|
|
|
/** |
|
1415
|
|
|
* Convert a object in folder data object to a custom format |
|
1416
|
|
|
* |
|
1417
|
|
|
* @param ObjectInFolderDataInterface $objectInFolder |
|
1418
|
|
|
* @return mixed |
|
1419
|
|
|
*/ |
|
1420
|
|
|
public function convertFromObjectInFolderData(ObjectInFolderDataInterface $objectInFolder) |
|
1421
|
|
|
{ |
|
1422
|
|
|
// TODO: Implement convertFromObjectInFolderData() method. |
|
1423
|
|
|
} |
|
1424
|
|
|
|
|
1425
|
|
|
/** |
|
1426
|
|
|
* Convert a object in folder list object to a custom format |
|
1427
|
|
|
* |
|
1428
|
|
|
* @param ObjectInFolderListInterface $objectInFolder |
|
1429
|
|
|
* @return mixed |
|
1430
|
|
|
*/ |
|
1431
|
|
|
public function convertFromObjectInFolderList(ObjectInFolderListInterface $objectInFolder) |
|
1432
|
|
|
{ |
|
1433
|
|
|
// TODO: Implement convertFromObjectInFolderList() method. |
|
1434
|
|
|
} |
|
1435
|
|
|
|
|
1436
|
|
|
/** |
|
1437
|
|
|
* Convert a object in folder container object to a custom format |
|
1438
|
|
|
* |
|
1439
|
|
|
* @param ObjectInFolderContainerInterface $container |
|
1440
|
|
|
* @return mixed |
|
1441
|
|
|
*/ |
|
1442
|
|
|
public function convertFromObjectInFolderContainer(ObjectInFolderContainerInterface $container) |
|
1443
|
|
|
{ |
|
1444
|
|
|
// TODO: Implement convertFromObjectInFolderContainer() method. |
|
1445
|
|
|
} |
|
1446
|
|
|
|
|
1447
|
|
|
/** |
|
1448
|
|
|
* Convert a object in parent data object to a custom format |
|
1449
|
|
|
* |
|
1450
|
|
|
* @param ObjectParentDataInterface $container |
|
1451
|
|
|
* @return mixed |
|
1452
|
|
|
*/ |
|
1453
|
|
|
public function convertFromObjectParentData(ObjectParentDataInterface $container) |
|
1454
|
|
|
{ |
|
1455
|
|
|
// TODO: Implement convertFromObjectParentData() method. |
|
1456
|
|
|
} |
|
1457
|
|
|
|
|
1458
|
|
|
/** |
|
1459
|
|
|
* Convert an extension feature object to a custom format |
|
1460
|
|
|
* |
|
1461
|
|
|
* @param ExtensionFeatureInterface $extensionFeature |
|
1462
|
|
|
* @return mixed |
|
1463
|
|
|
*/ |
|
1464
|
|
|
public function convertFromExtensionFeature(ExtensionFeatureInterface $extensionFeature) |
|
1465
|
|
|
{ |
|
1466
|
|
|
// TODO: Implement convertFromExtensionFeature() method. |
|
1467
|
|
|
} |
|
1468
|
|
|
|
|
1469
|
|
|
/** |
|
1470
|
|
|
* Convert given input data to a TypeChildren object |
|
1471
|
|
|
* |
|
1472
|
|
|
* @param array|null $data |
|
1473
|
|
|
* @return TypeDefinitionListInterface|null Returns a TypeDefinitionListInterface object or <code>null</code> |
|
1474
|
|
|
* if empty data is given. |
|
1475
|
|
|
*/ |
|
1476
|
|
|
public function convertTypeChildren(array $data = null) |
|
1477
|
|
|
{ |
|
1478
|
|
|
if (empty($data)) { |
|
1479
|
|
|
return null; |
|
1480
|
|
|
} |
|
1481
|
|
|
|
|
1482
|
|
|
$result = new TypeDefinitionList(); |
|
1483
|
|
|
$types = []; |
|
1484
|
|
|
|
|
1485
|
|
|
$typesList = $data[JSONConstants::JSON_TYPESLIST_TYPES] ?? []; |
|
1486
|
|
|
|
|
1487
|
|
|
foreach (array_filter($typesList, 'is_array') as $typeData) { |
|
1488
|
|
|
$type = $this->convertTypeDefinition($typeData); |
|
1489
|
|
|
if ($type !== null) { |
|
1490
|
|
|
$types[] = $type; |
|
1491
|
|
|
} |
|
1492
|
|
|
} |
|
1493
|
|
|
|
|
1494
|
|
|
$result->setList($types); |
|
1495
|
|
|
$result->setHasMoreItems($data[JSONConstants::JSON_TYPESLIST_HAS_MORE_ITEMS] ?? false); |
|
1496
|
|
|
$result->setNumItems($data[JSONConstants::JSON_TYPESLIST_NUM_ITEMS] ?? 0); |
|
1497
|
|
|
$result->setExtensions($this->convertExtension($data, JSONConstants::getTypesListKeys())); |
|
1498
|
|
|
|
|
1499
|
|
|
return $result; |
|
1500
|
|
|
} |
|
1501
|
|
|
|
|
1502
|
|
|
/** |
|
1503
|
|
|
* Convert given input data to a TypeDescendants object |
|
1504
|
|
|
* |
|
1505
|
|
|
* @param array|null $data |
|
1506
|
|
|
* @return TypeDefinitionContainerInterface[] Returns an array of TypeDefinitionContainerInterface objects |
|
1507
|
|
|
*/ |
|
1508
|
|
|
public function convertTypeDescendants(array $data = null) |
|
1509
|
|
|
{ |
|
1510
|
|
|
$result = []; |
|
1511
|
|
|
|
|
1512
|
|
|
if (empty($data)) { |
|
1513
|
|
|
return $result; |
|
1514
|
|
|
} |
|
1515
|
|
|
|
|
1516
|
|
|
foreach (array_filter($data, 'is_array') as $itemData) { |
|
1517
|
|
|
|
|
1518
|
|
|
$container = new TypeDefinitionContainer(); |
|
1519
|
|
|
|
|
1520
|
|
|
$typeDefinition = $this->convertTypeDefinition($itemData[JSONConstants::JSON_TYPESCONTAINER_TYPE] ?? []); |
|
1521
|
|
|
if ($typeDefinition !== null) { |
|
1522
|
|
|
$container->setTypeDefinition($typeDefinition); |
|
1523
|
|
|
} |
|
1524
|
|
|
|
|
1525
|
|
|
$container->setChildren( |
|
1526
|
|
|
$this->convertTypeDescendants($itemData[JSONConstants::JSON_TYPESCONTAINER_CHILDREN] ?? []) |
|
1527
|
|
|
); |
|
1528
|
|
|
|
|
1529
|
|
|
$container->setExtensions($this->convertExtension($data, JSONConstants::getTypesContainerKeys())); |
|
1530
|
|
|
|
|
1531
|
|
|
$result[] = $container; |
|
1532
|
|
|
} |
|
1533
|
|
|
|
|
1534
|
|
|
return $result; |
|
1535
|
|
|
} |
|
1536
|
|
|
|
|
1537
|
|
|
/** |
|
1538
|
|
|
* Convert given input data to a ObjectInFolderList object |
|
1539
|
|
|
* |
|
1540
|
|
|
* @param array|null $data |
|
1541
|
|
|
* @return null|ObjectInFolderList |
|
1542
|
|
|
*/ |
|
1543
|
|
|
public function convertObjectInFolderList(array $data = null) |
|
1544
|
|
|
{ |
|
1545
|
|
|
if (empty($data)) { |
|
1546
|
|
|
return null; |
|
1547
|
|
|
} |
|
1548
|
|
|
|
|
1549
|
|
|
$objectInFolderList = new ObjectInFolderList(); |
|
1550
|
|
|
$objectInFolderList->setObjects( |
|
1551
|
|
|
array_filter( |
|
1552
|
|
|
array_map( |
|
1553
|
|
|
[$this, 'convertObjectInFolder'], |
|
1554
|
|
|
$data[JSONConstants::JSON_OBJECTINFOLDERLIST_OBJECTS] ?? [] |
|
1555
|
|
|
), |
|
1556
|
|
|
function ($item) { return !empty($item); } |
|
1557
|
|
|
) |
|
1558
|
|
|
); |
|
1559
|
|
|
$objectInFolderList->setHasMoreItems((boolean) $data[JSONConstants::JSON_OBJECTINFOLDERLIST_HAS_MORE_ITEMS] ?? false); |
|
1560
|
|
|
$objectInFolderList->setNumItems((integer) $data[JSONConstants::JSON_OBJECTINFOLDERLIST_NUM_ITEMS] ?? count($objects)); |
|
|
|
|
|
|
1561
|
|
|
$objectInFolderList->setExtensions($this->convertExtension($data, JSONConstants::getObjectInFolderListKeys())); |
|
1562
|
|
|
|
|
1563
|
|
|
return $objectInFolderList; |
|
1564
|
|
|
} |
|
1565
|
|
|
|
|
1566
|
|
|
/** |
|
1567
|
|
|
* Convert given input data to a ObjectInFolderData object |
|
1568
|
|
|
* |
|
1569
|
|
|
* @param array|null $data |
|
1570
|
|
|
* @return ObjectInFolderData|null |
|
1571
|
|
|
*/ |
|
1572
|
|
View Code Duplication |
public function convertObjectInFolder(array $data = null) |
|
1573
|
|
|
{ |
|
1574
|
|
|
if (empty($data)) { |
|
1575
|
|
|
return null; |
|
1576
|
|
|
} |
|
1577
|
|
|
|
|
1578
|
|
|
$objectInFolderData = new ObjectInFolderData(); |
|
1579
|
|
|
$object = $this->convertObject($data[JSONConstants::JSON_OBJECTINFOLDER_OBJECT] ?? []); |
|
1580
|
|
|
|
|
1581
|
|
|
if ($object !== null) { |
|
1582
|
|
|
$objectInFolderData->setObject($object); |
|
1583
|
|
|
} |
|
1584
|
|
|
|
|
1585
|
|
|
$objectInFolderData->setPathSegment((string) $data[JSONConstants::JSON_OBJECTINFOLDER_PATH_SEGMENT] ?? null); |
|
1586
|
|
|
$objectInFolderData->setExtensions($this->convertExtension($data, JSONConstants::getObjectInFolderKeys())); |
|
1587
|
|
|
|
|
1588
|
|
|
return $objectInFolderData; |
|
1589
|
|
|
} |
|
1590
|
|
|
|
|
1591
|
|
|
/** |
|
1592
|
|
|
* Convert given input data to a list of ObjectParentData objects |
|
1593
|
|
|
* |
|
1594
|
|
|
* @param array|null $data |
|
1595
|
|
|
* @return ObjectParentData[] |
|
1596
|
|
|
*/ |
|
1597
|
|
View Code Duplication |
public function convertObjectParents(array $data = null) |
|
|
|
|
|
|
1598
|
|
|
{ |
|
1599
|
|
|
return array_filter( |
|
1600
|
|
|
array_map( |
|
1601
|
|
|
[$this, 'convertObjectParentData'], |
|
1602
|
|
|
(array) ($data ?? []) |
|
1603
|
|
|
), |
|
1604
|
|
|
function ($item) { |
|
1605
|
|
|
return !empty($item); |
|
1606
|
|
|
// @TODO once a logger is available we should log an INFO message if the parent data could not be converted |
|
1607
|
|
|
} |
|
1608
|
|
|
); |
|
1609
|
|
|
} |
|
1610
|
|
|
|
|
1611
|
|
|
/** |
|
1612
|
|
|
* Convert given input data to a ObjectParentData object |
|
1613
|
|
|
* |
|
1614
|
|
|
* @param array|null $data |
|
1615
|
|
|
* @return null|ObjectParentData |
|
1616
|
|
|
*/ |
|
1617
|
|
View Code Duplication |
public function convertObjectParentData(array $data = null) |
|
1618
|
|
|
{ |
|
1619
|
|
|
if (empty($data)) { |
|
1620
|
|
|
return null; |
|
1621
|
|
|
} |
|
1622
|
|
|
$parent = new ObjectParentData(); |
|
1623
|
|
|
|
|
1624
|
|
|
$object = $this->convertObject($data[JSONConstants::JSON_OBJECTPARENTS_OBJECT] ?? null); |
|
1625
|
|
|
if ($object !== null) { |
|
1626
|
|
|
$parent->setObject($object); |
|
1627
|
|
|
} |
|
1628
|
|
|
|
|
1629
|
|
|
$parent->setRelativePathSegment((string) ($data[JSONConstants::JSON_OBJECTPARENTS_RELATIVE_PATH_SEGMENT] ?? '')); |
|
1630
|
|
|
$parent->setExtensions($this->convertExtension($data, JSONConstants::getObjectParentsKeys())); |
|
1631
|
|
|
|
|
1632
|
|
|
return $parent; |
|
1633
|
|
|
} |
|
1634
|
|
|
|
|
1635
|
|
|
/** |
|
1636
|
|
|
* Convert given input data array to a ObjectList object |
|
1637
|
|
|
* |
|
1638
|
|
|
* @param array|null $data |
|
1639
|
|
|
* @return null|ObjectList |
|
1640
|
|
|
*/ |
|
1641
|
|
View Code Duplication |
public function convertObjectList(array $data = null) |
|
1642
|
|
|
{ |
|
1643
|
|
|
if (empty($data)) { |
|
1644
|
|
|
return null; |
|
1645
|
|
|
} |
|
1646
|
|
|
|
|
1647
|
|
|
$objectList = new ObjectList(); |
|
1648
|
|
|
$objects = []; |
|
1649
|
|
|
|
|
1650
|
|
|
foreach ((array) $data[JSONConstants::JSON_OBJECTLIST_OBJECTS] ?? [] as $objectData) { |
|
1651
|
|
|
$object = $this->convertObject($objectData); |
|
1652
|
|
|
|
|
1653
|
|
|
if ($object !== null) { |
|
1654
|
|
|
$objects[] = $object; |
|
1655
|
|
|
} |
|
1656
|
|
|
} |
|
1657
|
|
|
|
|
1658
|
|
|
$objectList->setObjects($objects); |
|
1659
|
|
|
|
|
1660
|
|
|
$objectList->setHasMoreItems( |
|
1661
|
|
|
(boolean) ($data[JSONConstants::JSON_OBJECTLIST_HAS_MORE_ITEMS] ?? false) |
|
1662
|
|
|
); |
|
1663
|
|
|
|
|
1664
|
|
|
if (isset($data[JSONConstants::JSON_OBJECTLIST_NUM_ITEMS])) { |
|
1665
|
|
|
$objectList->setNumItems((integer) $data[JSONConstants::JSON_OBJECTLIST_NUM_ITEMS]); |
|
1666
|
|
|
} |
|
1667
|
|
|
|
|
1668
|
|
|
$objectList->setExtensions($this->convertExtension($data, JSONConstants::getObjectListKeys())); |
|
1669
|
|
|
|
|
1670
|
|
|
return $objectList; |
|
1671
|
|
|
} |
|
1672
|
|
|
|
|
1673
|
|
|
/** |
|
1674
|
|
|
* Convert given input data array from query result to a ObjectList object |
|
1675
|
|
|
* |
|
1676
|
|
|
* @param array|null $data |
|
1677
|
|
|
* @return null|ObjectList |
|
1678
|
|
|
*/ |
|
1679
|
|
View Code Duplication |
public function convertQueryResultList(array $data = null) |
|
1680
|
|
|
{ |
|
1681
|
|
|
if (empty($data)) { |
|
1682
|
|
|
return null; |
|
1683
|
|
|
} |
|
1684
|
|
|
|
|
1685
|
|
|
$objectList = new ObjectList(); |
|
1686
|
|
|
$objects = []; |
|
1687
|
|
|
|
|
1688
|
|
|
foreach ((array) ($data[JSONConstants::JSON_QUERYRESULTLIST_RESULTS]) ?? [] as $objectData) { |
|
1689
|
|
|
$object = $this->convertObject($objectData); |
|
1690
|
|
|
|
|
1691
|
|
|
if ($object !== null) { |
|
1692
|
|
|
$objects[] = $object; |
|
1693
|
1 |
|
} |
|
1694
|
|
|
} |
|
1695
|
1 |
|
|
|
1696
|
|
|
$objectList->setObjects($objects); |
|
1697
|
|
|
$objectList->setHasMoreItems((boolean) ($data[JSONConstants::JSON_QUERYRESULTLIST_HAS_MORE_ITEMS] ?? false)); |
|
1698
|
|
|
|
|
1699
|
1 |
|
if (isset($data[JSONConstants::JSON_QUERYRESULTLIST_NUM_ITEMS])) { |
|
1700
|
1 |
|
$objectList->setNumItems((integer) $data[JSONConstants::JSON_QUERYRESULTLIST_NUM_ITEMS]); |
|
1701
|
|
|
} |
|
1702
|
1 |
|
|
|
1703
|
1 |
|
$objectList->setExtensions($this->convertExtension($data, JSONConstants::getQueryResultListKeys())); |
|
1704
|
1 |
|
|
|
1705
|
1 |
|
return $objectList; |
|
1706
|
|
|
} |
|
1707
|
1 |
|
|
|
1708
|
1 |
|
/** |
|
1709
|
1 |
|
* Convert given input data array to a ObjectList object |
|
1710
|
1 |
|
* |
|
1711
|
1 |
|
* @param array|null $data |
|
1712
|
1 |
|
* @return ObjectInFolderContainer[] |
|
1713
|
|
|
*/ |
|
1714
|
1 |
|
public function convertDescendants(array $data = null) |
|
1715
|
|
|
{ |
|
1716
|
1 |
|
return array_filter( |
|
1717
|
1 |
|
array_map( |
|
1718
|
1 |
|
[$this, 'convertDescendant'], |
|
1719
|
1 |
|
$data ?? [] |
|
1720
|
1 |
|
), |
|
1721
|
|
|
function ($item) { return !empty($item); } |
|
1722
|
1 |
|
); |
|
1723
|
1 |
|
} |
|
1724
|
1 |
|
|
|
1725
|
|
|
/** |
|
1726
|
1 |
|
* Convert given input data array to a ObjectInFolderContainer object |
|
1727
|
|
|
* |
|
1728
|
1 |
|
* @param array|null $data |
|
1729
|
|
|
* @return null|ObjectInFolderContainer |
|
1730
|
|
|
* @throws CmisRuntimeException |
|
1731
|
|
|
*/ |
|
1732
|
|
|
public function convertDescendant(array $data = null) |
|
1733
|
|
|
{ |
|
1734
|
|
|
if (empty($data)) { |
|
1735
|
|
|
return null; |
|
1736
|
|
|
} |
|
1737
|
2 |
|
|
|
1738
|
|
|
$object = $this->convertObjectInFolder($data[JSONConstants::JSON_OBJECTINFOLDERCONTAINER_OBJECT] ?? null); |
|
1739
|
2 |
|
|
|
1740
|
|
|
if ($object === null) { |
|
1741
|
|
|
throw new CmisRuntimeException('Given data could not be converted to ObjectInFolder!'); |
|
1742
|
|
|
} |
|
1743
|
2 |
|
|
|
1744
|
|
|
$objectInFolderContainer = new ObjectInFolderContainer($object); |
|
1745
|
2 |
|
|
|
1746
|
2 |
|
$objectInFolderContainer->setChildren( |
|
1747
|
|
|
array_filter( |
|
1748
|
2 |
|
array_map( |
|
1749
|
2 |
|
[$this, 'convertDescendant'], |
|
1750
|
2 |
|
(array) ($data[JSONConstants::JSON_OBJECTINFOLDERCONTAINER_CHILDREN] ?? []) |
|
1751
|
2 |
|
), |
|
1752
|
|
|
function ($item) { return !empty($item); } |
|
1753
|
2 |
|
) |
|
1754
|
2 |
|
); |
|
1755
|
2 |
|
|
|
1756
|
|
|
$objectInFolderContainer->setExtensions( |
|
1757
|
2 |
|
$this->convertExtension($data, JSONConstants::getObjectInFolderContainerKeys()) |
|
1758
|
|
|
); |
|
1759
|
2 |
|
|
|
1760
|
|
|
return $objectInFolderContainer; |
|
1761
|
|
|
} |
|
1762
|
|
|
|
|
1763
|
|
|
/** |
|
1764
|
|
|
* Converts FailedToDelete ids. |
|
1765
|
|
|
* |
|
1766
|
|
|
* @param array|null $data |
|
1767
|
|
|
* @return FailedToDeleteData |
|
1768
|
1 |
|
*/ |
|
1769
|
|
View Code Duplication |
public function convertFailedToDelete(array $data = null) |
|
|
|
|
|
|
1770
|
1 |
|
{ |
|
1771
|
|
|
$result = new FailedToDeleteData(); |
|
1772
|
|
|
|
|
1773
|
1 |
|
if (empty($data)) { |
|
1774
|
|
|
return $result; |
|
1775
|
1 |
|
} |
|
1776
|
1 |
|
|
|
1777
|
|
|
$result->setIds(array_map('strval', $data[JSONConstants::JSON_FAILEDTODELETE_ID] ?? [])); |
|
1778
|
|
|
$result->setExtensions($this->convertExtension($data, JSONConstants::getFailedToDeleteKeys())); |
|
1779
|
1 |
|
|
|
1780
|
1 |
|
return $result; |
|
1781
|
1 |
|
} |
|
1782
|
1 |
|
|
|
1783
|
|
|
/** |
|
1784
|
1 |
|
* @return BindingsObjectFactory |
|
1785
|
|
|
* @codeCoverageIgnore |
|
1786
|
|
|
*/ |
|
1787
|
|
|
protected function getBindingsObjectFactory() |
|
1788
|
|
|
{ |
|
1789
|
|
|
return new BindingsObjectFactory(); |
|
1790
|
|
|
} |
|
1791
|
|
|
} |
|
1792
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.