GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 42c65a...a98f71 )
by
unknown
07:18
created

JsonConverter::convertObject()   F

Complexity

Conditions 24
Paths 3025

Size

Total Lines 101
Code Lines 55

Duplication

Lines 16
Ratio 15.84 %

Code Coverage

Tests 68
CRAP Score 25.5536

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 16
loc 101
ccs 68
cts 79
cp 0.8608
rs 2
cc 24
eloc 55
nc 3025
nop 1
crap 25.5536

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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