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 ( e7fb79...adc388 )
by
unknown
87:37 queued 75:31
created

ObjectService::createRelationship()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 17

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 23
loc 23
ccs 0
cts 7
cp 0
rs 9.0856
cc 2
eloc 17
nc 2
nop 6
crap 6
1
<?php
2
namespace Dkd\PhpCmis\Bindings\Browser;
3
4
/*
5
 * This file is part of php-cmis-client.
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\PhpCmis\Constants;
14
use Dkd\PhpCmis\Data\AclInterface;
15
use Dkd\PhpCmis\Data\AllowableActionsInterface;
16
use Dkd\PhpCmis\Data\BulkUpdateObjectIdAndChangeTokenInterface;
17
use Dkd\PhpCmis\Data\ExtensionDataInterface;
18
use Dkd\PhpCmis\Data\FailedToDeleteDataInterface;
19
use Dkd\PhpCmis\Data\ObjectDataInterface;
20
use Dkd\PhpCmis\Data\PropertiesInterface;
21
use Dkd\PhpCmis\Data\RenditionDataInterface;
22
use Dkd\PhpCmis\Enum\IncludeRelationships;
23
use Dkd\PhpCmis\Enum\UnfileObject;
24
use Dkd\PhpCmis\Enum\VersioningState;
25
use Dkd\PhpCmis\Exception\CmisInvalidArgumentException;
26
use Dkd\PhpCmis\ObjectServiceInterface;
27
use Dkd\PhpCmis\PropertyIds;
28
use Dkd\PhpCmis\SessionParameter;
29
use GuzzleHttp\Stream\LimitStream;
30
use GuzzleHttp\Message\Response;
31
use GuzzleHttp\Stream\Stream;
32
use GuzzleHttp\Stream\StreamInterface;
33
34
/**
35
 * Object Service Browser Binding client.
36
 */
37
class ObjectService extends AbstractBrowserBindingService implements ObjectServiceInterface
38
{
39
    /**
40
     * L1 cache for objects. Fills with two levels:
41
     *
42
     * - First level key is the object ID, path or other singular identifier of object(s)
43
     * - Second level key is a hash of context arguments used to retrieve the object(s)
44
     *
45
     * @var array
46
     */
47
    protected $objectCache = [];
48
49
    /**
50
     * Appends the content stream to the content of the document.
51
     *
52
     * The stream in contentStream is consumed but not closed by this method.
53
     *
54
     * @param string $repositoryId the identifier for the repository
55
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
56
     * @param StreamInterface $contentStream The content stream to append
57
     * @param boolean $isLastChunk Indicates if this content stream is the last chunk
58
     * @param string|null $changeToken The last change token of this object that the client received.
59
     *      The repository might return a new change token (default is <code>null</code>)
60
     * @param ExtensionDataInterface|null $extension
61
     */
62
    public function appendContentStream(
63
        $repositoryId,
64
        & $objectId,
65
        StreamInterface $contentStream,
66
        $isLastChunk,
67
        & $changeToken = null,
68
        ExtensionDataInterface $extension = null
69
    ) {
70
        // TODO: Implement appendContentStream() method.
71
    }
72
73
    /**
74
     * Updates properties and secondary types of one or more objects.
75
     *
76
     * @param string $repositoryId the identifier for the repository
77
     * @param BulkUpdateObjectIdAndChangeTokenInterface[] $objectIdsAndChangeTokens
78
     * @param PropertiesInterface $properties
79
     * @param string[] $addSecondaryTypeIds the secondary types to apply
80
     * @param string[] $removeSecondaryTypeIds the secondary types to remove
81
     * @param ExtensionDataInterface|null $extension
82
     * @return BulkUpdateObjectIdAndChangeTokenInterface[]
83
     */
84
    public function bulkUpdateProperties(
85
        $repositoryId,
86
        array $objectIdsAndChangeTokens,
87
        PropertiesInterface $properties,
88
        array $addSecondaryTypeIds,
89
        array $removeSecondaryTypeIds,
90
        ExtensionDataInterface $extension = null
91
    ) {
92
        // TODO: Implement bulkUpdateProperties() method.
93
    }
94
95
    /**
96
     * @param string $action
97
     * @param PropertiesInterface $properties
98
     * @param string[] $policies
99
     * @param AclInterface $addAces
0 ignored issues
show
Documentation introduced by
Should the type for parameter $addAces not be null|AclInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
100
     * @param AclInterface $removeAces
0 ignored issues
show
Documentation introduced by
Should the type for parameter $removeAces not be null|AclInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
101
     * @param ExtensionDataInterface $extension
0 ignored issues
show
Documentation introduced by
Should the type for parameter $extension not be null|ExtensionDataInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
102
     * @return array
103
     */
104 9
    protected function createQueryArray(
105
        $action,
106
        PropertiesInterface $properties,
107
        array $policies = [],
108
        AclInterface $addAces = null,
109
        AclInterface $removeAces = null,
110
        ExtensionDataInterface $extension = null
0 ignored issues
show
Unused Code introduced by
The parameter $extension is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    ) {
112 9
        $queryArray = array_replace(
113
            [
114 9
                Constants::CONTROL_CMISACTION => $action,
115 9
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
116 9
            ],
117 9
            $this->convertPropertiesToQueryArray($properties),
118 9
            $this->convertPolicyIdArrayToQueryArray($policies)
119 9
        );
120 9
        if (!empty($removeAces)) {
121 5
            $queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
122 5
                $removeAces,
123 5
                Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
124
                Constants::CONTROL_REMOVE_ACE_PERMISSION
125 5
            ));
126 5
        }
127 9 View Code Duplication
        if (!empty($addAces)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128 5
            $queryArray = array_replace($queryArray, $this->convertAclToQueryArray(
129 5
                $addAces,
130 5
                Constants::CONTROL_ADD_ACE_PRINCIPAL,
131
                Constants::CONTROL_ADD_ACE_PERMISSION
132 5
            ));
133 5
        }
134 9
        return $queryArray;
135
    }
136
137
    /**
138
     * Creates a document object of the specified type (given by the cmis:objectTypeId property)
139
     * in the (optionally) specified location.
140
     *
141
     * @param string $repositoryId the identifier for the repository
142
     * @param PropertiesInterface $properties the property values that must be applied to the newly
143
     *      created document object
144
     * @param string|null $folderId if specified, the identifier for the folder that must be the parent
145
     *      folder for the newly created document object
146
     * @param StreamInterface|null $contentStream the content stream that must be stored for the newly
147
     *      created document object
148
     * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object
149
     *      must be (default is <code>VersioningState::MAJOR</code>)
150
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
151
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
152
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
153
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
154
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
155
     * @param ExtensionDataInterface|null $extension
156
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
157
     *      result (which should not happen)
158
     */
159 3
    public function createDocument(
160
        $repositoryId,
161
        PropertiesInterface $properties,
162
        $folderId = null,
163
        StreamInterface $contentStream = null,
164
        VersioningState $versioningState = null,
165
        array $policies = [],
166
        AclInterface $addAces = null,
167
        AclInterface $removeAces = null,
168
        ExtensionDataInterface $extension = null
169
    ) {
170 3 View Code Duplication
        if ($folderId === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171 1
            $url = $this->getRepositoryUrl($repositoryId);
172 1
        } else {
173 2
            $url = $this->getObjectUrl($repositoryId, $folderId);
174
        }
175
176 3
        $queryArray = $this->createQueryArray(
177 3
            Constants::CMISACTION_CREATE_DOCUMENT,
178 3
            $properties,
179 3
            $policies,
180 3
            $addAces,
181 3
            $removeAces,
182
            $extension
183 3
        );
184 3
        if ($versioningState !== null) {
185 2
            $queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
186 2
        }
187
188 3
        $newObject = $this->getJsonConverter()->convertObject(
189 3
            (array) $this->postJson(
190 3
                $url,
191 3
                array_merge(
192 3
                    $queryArray,
193 3
                    ['body' => $contentStream]
194 3
                )
195 3
            )
196
        );
197 3
198
        if ($newObject) {
199 3
            $newObjectId = $newObject->getId();
200
            if ($contentStream) {
201 3
                $this->setContentStream($repositoryId, $newObjectId, $contentStream);
202 3
            }
203 3
            return $newObjectId;
204 2
        }
205 2
        return null;
206 3
    }
207
208
    /**
209
     * Creates a document object as a copy of the given source document in the (optionally) specified location.
210
     *
211
     * @param string $repositoryId the identifier for the repository
212
     * @param string $sourceId the identifier for the source document
213
     * @param PropertiesInterface $properties the property values that must be applied to the newly
214
     *      created document object
215
     * @param string|null $folderId if specified, the identifier for the folder that must be the parent folder for the
216
     *      newly created document object
217
     * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object
218
     *      must be (default is <code>VersioningState::MAJOR</code>)
219
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
220
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
221
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
222
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
223
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
224
     * @param ExtensionDataInterface|null $extension
225
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
226
     *      result (which should not happen)
227
     */
228
    public function createDocumentFromSource(
229
        $repositoryId,
230
        $sourceId,
231 2
        PropertiesInterface $properties,
232
        $folderId = null,
233
        VersioningState $versioningState = null,
234
        array $policies = [],
235
        AclInterface $addAces = null,
236
        AclInterface $removeAces = null,
237
        ExtensionDataInterface $extension = null
238
    ) {
239 View Code Duplication
        if ($folderId === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
240
            $url = $this->getRepositoryUrl($repositoryId);
241
        } else {
242 2
            $url = $this->getObjectUrl($repositoryId, $folderId);
243
        }
244
245 2
        $queryArray = $this->createQueryArray(
246
            Constants::CMISACTION_CREATE_DOCUMENT_FROM_SOURCE,
247
            $properties,
248 2
            $policies,
249 2
            $addAces,
250 2
            $removeAces,
251 2
            $extension
252 2
        );
253 2
        $queryArray[Constants::PARAM_SOURCE_ID] = (string) $sourceId;
254
        if ($versioningState !== null) {
255 2
            $queryArray[Constants::PARAM_VERSIONING_STATE] = (string) $versioningState;
256 2
        }
257 2
258 1
        $newObject = $this->getJsonConverter()->convertObject((array) $this->postJson($url, $queryArray));
259 1
260 2
        return ($newObject === null) ? null : $newObject->getId();
261
    }
262 2
263
    /**
264 2
     * Creates a folder object of the specified type (given by the cmis:objectTypeId property) in
265
     * the specified location.
266
     *
267
     * @param string $repositoryId the identifier for the repository
268
     * @param PropertiesInterface $properties the property values that must be applied to the newly
269
     *      created document object
270
     * @param string $folderId if specified, the identifier for the folder that must be the parent folder for the
271
     *      newly created document object
272
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
273
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
274
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
275
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
276
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
277
     * @param ExtensionDataInterface|null $extension
278
     * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty
279
     *      result (which should not happen)
280
     */
281 View Code Duplication
    public function createFolder(
282
        $repositoryId,
283
        PropertiesInterface $properties,
284
        $folderId,
285 2
        array $policies = [],
286
        AclInterface $addAces = null,
287
        AclInterface $removeAces = null,
288
        ExtensionDataInterface $extension = null
289
    ) {
290
        $url = $this->getObjectUrl($repositoryId, $folderId);
291
        $queryArray = $this->createQueryArray(
292
            Constants::CMISACTION_CREATE_FOLDER,
293
            $properties,
294 2
            $policies,
295 2
            $addAces,
296 2
            $removeAces,
297 2
            $extension
298 2
        );
299 2
300 2
        $newObject = $this->getJsonConverter()->convertObject((array) $this->postJson($url, $queryArray));
301
302 2
        return ($newObject === null) ? null : $newObject->getId();
303
    }
304 2
305
    /**
306 2
     * Creates an item object of the specified type (given by the cmis:objectTypeId property).
307
     *
308 2
     * @param string $repositoryId The identifier for the repository
309
     * @param PropertiesInterface $properties The property values that must be applied to the newly
310
     *      created document object
311
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
312
     *      newly created document object
313
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
314
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
315
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
316
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
317
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
318
     * @param ExtensionDataInterface|null $extension
319
     * @return string|null Returns the new item id or <code>null</code> if the repository sent an empty
320
     *      result (which should not happen)
321
     */
322
    public function createItem(
323
        $repositoryId,
324
        PropertiesInterface $properties,
325
        $folderId = null,
326
        array $policies = [],
327
        AclInterface $addAces = null,
328 2
        AclInterface $removeAces = null,
329
        ExtensionDataInterface $extension = null
330
    ) {
331
        if ($folderId === null) {
332
            $url = $this->getRepositoryUrl($repositoryId);
333
        } else {
334
            $url = $this->getObjectUrl($repositoryId, $folderId);
335
        }
336
337 2
        $queryArray = $this->createQueryArray(
338
            Constants::CMISACTION_CREATE_ITEM,
339
            $properties,
340 2
            $policies,
341
            $addAces,
342
            $removeAces,
343 2
            $extension
344 2
        );
345 2
346 2
        $newObject = $this->getJsonConverter()->convertObject((array) $this->postJson($url, $queryArray));
347 2
348 2
        return ($newObject === null) ? null : $newObject->getId();
349
    }
350 2
351
    /**
352 2
     * Creates a policy object of the specified type (given by the cmis:objectTypeId property).
353
     *
354 2
     * @param string $repositoryId The identifier for the repository
355
     * @param PropertiesInterface $properties The property values that must be applied to the newly
356 2
     *      created document object
357
     * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the
358
     *      newly created document object
359
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
360
     * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object,
361
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
362
     * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object,
363
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
364
     * @param ExtensionDataInterface|null $extension
365
     * @return string The id of the newly-created policy.
366
     */
367
    public function createPolicy(
368
        $repositoryId,
369
        PropertiesInterface $properties,
370
        $folderId = null,
371
        array $policies = [],
372
        AclInterface $addAces = null,
373
        AclInterface $removeAces = null,
374
        ExtensionDataInterface $extension = null
375
    ) {
376
        // TODO: Implement createPolicy() method.
377
    }
378
379
    /**
380
     * Creates a relationship object of the specified type (given by the cmis:objectTypeId property).
381
     *
382
     * @param string $repositoryId the identifier for the repository
383
     * @param PropertiesInterface $properties the property values that must be applied to the newly
384
     *      created document object
385
     * @param string[] $policies a list of policy IDs that must be applied to the newly created document object
386
     * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object,
387
     *      either using the ACL from folderId if specified, or being applied if no folderId is specified
388
     * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object,
389
     *      either using the ACL from folderId if specified, or being ignored if no folderId is specified
390
     * @param ExtensionDataInterface|null $extension
391
     * @return string|null Returns the new item id of the relationship object or <code>null</code> if the repository
392
     *      sent an empty result (which should not happen)
393
     */
394 View Code Duplication
    public function createRelationship(
395
        $repositoryId,
396
        PropertiesInterface $properties,
397
        array $policies = [],
398
        AclInterface $addAces = null,
399
        AclInterface $removeAces = null,
400
        ExtensionDataInterface $extension = null
401
    ) {
402
        $url = $this->getRepositoryUrl($repositoryId);
403
404
        $queryArray = $this->createQueryArray(
405
            Constants::CMISACTION_CREATE_RELATIONSHIP,
406
            $properties,
407
            $policies,
408
            $addAces,
409
            $removeAces,
410
            $extension
411
        );
412
413
        $newObject = $this->getJsonConverter()->convertObject((array) $this->postJson($url, $queryArray));
414
415
        return ($newObject === null) ? null : $newObject->getId();
416
    }
417
418
    /**
419
     * Deletes the content stream for the specified document object.
420
     *
421
     * @param string $repositoryId the identifier for the repository
422
     * @param string $objectId the identifier for the object. The repository might return a different/new object id
423
     * @param string|null $changeToken the last change token of this object that the client received.
424
     *      The repository might return a new change token (default is <code>null</code>)
425
     * @param ExtensionDataInterface|null $extension
426
     * @throws CmisInvalidArgumentException If $objectId is empty
427
     */
428
    public function deleteContentStream(
429
        $repositoryId,
430
        & $objectId,
431
        & $changeToken = null,
432
        ExtensionDataInterface $extension = null
433
    ) {
434
        if (empty($objectId)) {
435
            throw new CmisInvalidArgumentException('Object id must not be empty!');
436
        }
437
438 3
        $this->flushCached();
439
440
        $url = $this->getObjectUrl($repositoryId, $objectId);
441
442
        $url->getQuery()->modify(
443
            [
444 3
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_CONTENT,
445
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
446
            ]
447
        );
448 3
449 View Code Duplication
        if ($changeToken !== null && !$this->getSession()->get(SessionParameter::OMIT_CHANGE_TOKENS, false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
450 3
            $url->getQuery()->modify([Constants::PARAM_CHANGE_TOKEN => $changeToken]);
451
        }
452 3
453
        $newObject = $this->getJsonConverter()->convertObject((array) $this->postJson($url));
454 3
455 3
        // $objectId was passed by reference. The value is changed here to new object id
456 3
        $objectId = null;
457 3 View Code Duplication
        if ($newObject !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
458
            $objectId = $newObject->getId();
459 3
            $newObjectProperties = $newObject->getProperties()->getProperties();
460 1
            if ($changeToken !== null && count($newObjectProperties) > 0) {
461 1
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
462
                // $changeToken was passed by reference. The value is changed here
463 3
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
464 3
            }
465
        }
466
    }
467 3
468 3
    /**
469 3
     * Deletes the specified object.
470 3
     *
471 3
     * @param string $repositoryId the identifier for the repository
472 2
     * @param string $objectId the identifier for the object
473
     * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only
474 2
     *      the document object specified (default is <code>true</code>)
475 2
     * @param ExtensionDataInterface|null $extension
476 3
     */
477 3 View Code Duplication
    public function deleteObject(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
478
        $repositoryId,
479
        $objectId,
480
        $allVersions = true,
481
        ExtensionDataInterface $extension = null
482
    ) {
483
        $url = $this->getObjectUrl($repositoryId, $objectId);
484
        $url->getQuery()->modify(
485
            [
486
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE,
487
                Constants::PARAM_ALL_VERSIONS => $allVersions ? 'true' : 'false',
488 2
            ]
489
        );
490
491
        $this->post($url);
492
        $this->flushCached();
493
    }
494 2
495 2
    /**
496
     * Deletes the specified folder object and all of its child- and descendant-objects.
497 2
     *
498 2
     * @param string $repositoryId the identifier for the repository
499
     * @param string $folderId the identifier for the folder
500 2
     * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only
501
     *      the document object specified (default is <code>true</code>)
502 2
     * @param UnfileObject|null $unfileObjects defines how the repository must process file-able child- or
503 2
     *      descendant-objects (default is <code>UnfileObject::DELETE</code>)
504 2
     * @param boolean $continueOnFailure If <code>true</code>, then the repository should continue attempting to
505
     *      perform this operation even if deletion of a child- or descendant-object in the specified folder cannot
506
     *      be deleted
507
     * @param ExtensionDataInterface|null $extension
508
     * @return FailedToDeleteDataInterface Returns a list of object ids that could not be deleted
509
     */
510
    public function deleteTree(
511
        $repositoryId,
512
        $folderId,
513
        $allVersions = true,
514
        UnfileObject $unfileObjects = null,
515
        $continueOnFailure = false,
516
        ExtensionDataInterface $extension = null
517
    ) {
518
        $url = $this->getObjectUrl($repositoryId, $folderId);
519
        $url->getQuery()->modify(
520
            [
521 4
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_TREE,
522
                Constants::PARAM_FOLDER_ID => $folderId,
523
                Constants::PARAM_ALL_VERSIONS => $allVersions ? 'true' : 'false',
524
                Constants::PARAM_CONTINUE_ON_FAILURE => $continueOnFailure ? 'true' : 'false'
525
            ]
526
        );
527
528
        if ($unfileObjects !== null) {
529 4
            $url->getQuery()->modify([Constants::PARAM_UNFILE_OBJECTS => (string) $unfileObjects]);
530 4
        }
531
532 4
        return $this->getJsonConverter()->convertFailedToDelete($this->postJson($url));
533 4
    }
534 4
535 4
    /**
536 4
     * Gets the list of allowable actions for an object.
537 4
     *
538
     * @param string $repositoryId the identifier for the repository
539 4
     * @param string $objectId the identifier for the object
540 1
     * @param ExtensionDataInterface|null $extension
541 1
     * @return AllowableActionsInterface
542
     */
543 4
    public function getAllowableActions($repositoryId, $objectId, ExtensionDataInterface $extension = null)
544
    {
545 4
        // TODO: Implement getAllowableActions() method.
546 4
    }
547 4
548
    /**
549 4
     * Gets the content stream for the specified document object, or gets a rendition stream for
550 4
     * a specified rendition of a document or folder object.
551
     *
552
     * @param string $repositoryId the identifier for the repository
553
     * @param string $objectId the identifier for the object
554
     * @param string|null $streamId The identifier for the rendition stream, when used to get a rendition stream.
555
     *      For documents, if not provided then this method returns the content stream. For folders,
556
     *      it MUST be provided.
557
     * @param integer|null $offset
558
     * @param integer|null $length
559
     * @param ExtensionDataInterface|null $extension
560
     * @return StreamInterface|null
561
     * @throws CmisInvalidArgumentException If object id is empty
562
     */
563
    public function getContentStream(
564
        $repositoryId,
565
        $objectId,
566
        $streamId = null,
567
        $offset = null,
568
        $length = null,
569
        ExtensionDataInterface $extension = null
570
    ) {
571
        if (empty($objectId)) {
572
            throw new CmisInvalidArgumentException('Object id must not be empty!');
573
        }
574
575
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_CONTENT);
576
577
        if ($streamId !== null) {
578
            $url->getQuery()->modify([Constants::PARAM_STREAM_ID => $streamId]);
579
        }
580
581 3
        /** @var Response $response */
582
        $response = $this->getHttpInvoker()->get($url);
583
584
        $contentStream = $response->getBody();
585
        if (!$contentStream instanceof StreamInterface) {
586
            return null;
587
        }
588
589 3
        if ($offset !== null) {
590
            $contentStream = new LimitStream($contentStream, $length !== null ? $length : - 1, $offset);
591
        }
592
593 3
        return $contentStream;
594
    }
595 3
596 1
    /**
597 1
     * Gets the specified information for the object specified by id.
598
     *
599
     * @param string $repositoryId the identifier for the repository
600 3
     * @param string $objectId the identifier for the object
601
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
602 3
     *      returned by the repository (default is repository specific)
603 3
     * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable
604
     *      actions for the object (default is <code>false</code>)
605
     * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects
606
     *      participate must be returned (default is <code>IncludeRelationships::NONE</code>)
607 3
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
608 1
     *      matches this filter (default is "cmis:none")
609 1
     * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for
610
     *      the object (default is <code>false</code>)
611 3
     * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object
612
     *      (default is <code>false</code>)
613
     * @param ExtensionDataInterface|null $extension
614
     * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code>
615
     *     if the repository response was empty
616
     */
617 View Code Duplication
    public function getObject(
618
        $repositoryId,
619
        $objectId,
620
        $filter = null,
621
        $includeAllowableActions = false,
622
        IncludeRelationships $includeRelationships = null,
623
        $renditionFilter = Constants::RENDITION_NONE,
624
        $includePolicyIds = false,
625
        $includeAcl = false,
626
        ExtensionDataInterface $extension = null
627
    ) {
628
        $cacheKey = $this->createCacheKey(
629
            $objectId,
630
            [
631
                $repositoryId,
632
                $filter,
633
                $includeAllowableActions,
634
                $includeRelationships,
635 3
                $renditionFilter,
636
                $includePolicyIds,
637
                $includeAcl,
638
                $extension,
639
                $this->getSuccinct()
640
            ]
641
        );
642
        if ($this->isCached($cacheKey)) {
643
            return $this->getCached($cacheKey);
644
        }
645
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_OBJECT);
646 3
        $url->getQuery()->modify(
647 3
            [
648
                Constants::PARAM_ALLOWABLE_ACTIONS => $includeAllowableActions ? 'true' : 'false',
649 3
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
650 3
                Constants::PARAM_POLICY_IDS => $includePolicyIds ? 'true' : 'false',
651 3
                Constants::PARAM_ACL => $includeAcl ? 'true' : 'false',
652 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
653 3
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
654 3
            ]
655 3
        );
656 3
657 3
        if (!empty($filter)) {
658 3
            $url->getQuery()->modify([Constants::PARAM_FILTER => (string) $filter]);
659 3
        }
660 3
661
        if ($includeRelationships !== null) {
662
            $url->getQuery()->modify([Constants::PARAM_RELATIONSHIPS => (string) $includeRelationships]);
663 3
        }
664 3
665
        $responseData = (array) $this->readJson($url);
666 3
667 3
        return $this->cache(
668 3
            $cacheKey,
669 3
            $this->getJsonConverter()->convertObject($responseData)
670 3
        );
671 3
    }
672 3
673 3
    /**
674
     * Gets the specified information for the object specified by path.
675 3
     *
676 2
     * @param string $repositoryId the identifier for the repository
677 2
     * @param string $path the path to the object
678
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
679 3
     *      returned by the repository (default is repository specific)
680 2
     * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable
681 2
     *      actions for the object (default is <code>false</code>)
682
     * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects
683 3
     *      participate must be returned (default is <code>IncludeRelationships::NONE</code>)
684
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
685 3
     *      matches this filter (default is "cmis:none")
686 3
     * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for
687 3
     *      the object (default is <code>false</code>)
688 3
     * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object
689
     *      (default is <code>false</code>)
690
     * @param ExtensionDataInterface|null $extension
691
     * @return ObjectDataInterface|null Returns object of type <code>ObjectDataInterface</code> or <code>null</code>
692
     *      if the repository response was empty
693
     */
694 View Code Duplication
    public function getObjectByPath(
695
        $repositoryId,
696
        $path,
697
        $filter = null,
698
        $includeAllowableActions = false,
699
        IncludeRelationships $includeRelationships = null,
700
        $renditionFilter = Constants::RENDITION_NONE,
701
        $includePolicyIds = false,
702
        $includeAcl = false,
703
        ExtensionDataInterface $extension = null
704
    ) {
705
        $cacheKey = $this->createCacheKey(
706
            $path,
707
            [
708
                $repositoryId,
709
                $filter,
710
                $includeAllowableActions,
711
                $includeRelationships,
712 3
                $renditionFilter,
713
                $includePolicyIds,
714
                $includeAcl,
715
                $extension,
716
                $this->getSuccinct()
717
            ]
718
        );
719
        if ($this->isCached($cacheKey)) {
720
            return $this->getCached($cacheKey);
721
        }
722
723 3
        $url = $this->getPathUrl($repositoryId, $path, Constants::SELECTOR_OBJECT);
724 3
        $url->getQuery()->modify(
725
            [
726 3
                Constants::PARAM_ALLOWABLE_ACTIONS => $includeAllowableActions ? 'true' : 'false',
727 3
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
728 3
                Constants::PARAM_POLICY_IDS => $includePolicyIds ? 'true' : 'false',
729 3
                Constants::PARAM_ACL => $includeAcl ? 'true' : 'false',
730 3
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
731 3
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
732 3
            ]
733 3
        );
734 3
735 3
        if (!empty($filter)) {
736 3
            $url->getQuery()->modify([Constants::PARAM_FILTER => (string) $filter]);
737 3
        }
738
739
        if ($includeRelationships !== null) {
740
            $url->getQuery()->modify([Constants::PARAM_RELATIONSHIPS => (string) $includeRelationships]);
741 3
        }
742 3
743
        $responseData = (array) $this->readJson($url);
744 3
745 3
        return $this->cache(
746 3
            $cacheKey,
747 3
            $this->getJsonConverter()->convertObject($responseData)
748 3
        );
749 3
    }
750 3
751 3
    /**
752
     * Gets the list of properties for an object.
753 3
     *
754 2
     * @param string $repositoryId the identifier for the repository
755 2
     * @param string $objectId the identifier for the object
756
     * @param string|null $filter a comma-separated list of query names that defines which properties must be
757 3
     *      returned by the repository (default is repository specific)
758 2
     * @param ExtensionDataInterface|null $extension
759 2
     * @return PropertiesInterface
760
     */
761 3
    public function getProperties(
762
        $repositoryId,
763 3
        $objectId,
764 3
        $filter = null,
765 3
        ExtensionDataInterface $extension = null
766 3
    ) {
767
        $cacheKey = $this->createCacheKey(
768
            $objectId,
769
            [
770
                $repositoryId,
771
                $filter,
772
                $extension,
773
                $this->getSuccinct()
774
            ]
775
        );
776
777
        if ($this->isCached($cacheKey)) {
778
            return $this->getCached($cacheKey);
779 2
        }
780
781
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_PROPERTIES);
782
        $url->getQuery()->modify(
783
            [
784
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false',
785 2
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
786 2
            ]
787
        );
788 2
789 2
        if (!empty($filter)) {
790 2
            $url->getQuery()->modify([Constants::PARAM_FILTER => (string) $filter]);
791 2
        }
792 2
793 2
        $responseData = (array) $this->readJson($url);
794
795 2
        if ($this->getSuccinct()) {
796
            $objectData = $this->getJsonConverter()->convertSuccinctProperties($responseData);
797
        } else {
798
            $objectData = $this->getJsonConverter()->convertProperties($responseData);
799 2
        }
800 2
801
        return $this->cache(
802 2
            $cacheKey,
803 2
            $objectData
804 2
        );
805 2
    }
806
807 2
    /**
808 1
     * Gets the list of associated renditions for the specified object.
809 1
     * Only rendition attributes are returned, not rendition stream.
810
     *
811 2
     * @param string $repositoryId the identifier for the repository
812
     * @param string $objectId the identifier for the object
813 2
     * @param string $renditionFilter indicates what set of renditions the repository must return whose kind
814
     *      matches this filter (default is "cmis:none")
815
     * @param integer|null $maxItems the maximum number of items to return in a response
816 2
     *       (default is repository specific)
817
     * @param integer $skipCount number of potential results that the repository MUST skip/page over before
818
     *      returning any results (default is 0)
819 2
     * @param ExtensionDataInterface|null $extension
820 2
     * @return RenditionDataInterface[]
821
     * @throws CmisInvalidArgumentException If object id is empty or skip count not of type integer
822 2
     */
823
    public function getRenditions(
824
        $repositoryId,
825
        $objectId,
826
        $renditionFilter = Constants::RENDITION_NONE,
827
        $maxItems = null,
828
        $skipCount = 0,
829
        ExtensionDataInterface $extension = null
830
    ) {
831
        if (empty($objectId)) {
832
            throw new CmisInvalidArgumentException('Object id must not be empty!');
833
        }
834
835
        if (!is_int($skipCount)) {
836
            throw new CmisInvalidArgumentException('Skip count must be of type integer!');
837
        }
838
839
        $url = $this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_RENDITIONS);
840
        $url->getQuery()->modify(
841 2
            [
842
                Constants::PARAM_RENDITION_FILTER => $renditionFilter,
843
                Constants::PARAM_SKIP_COUNT => (string) $skipCount,
844
            ]
845
        );
846
847
        if ($maxItems !== null) {
848
            $url->getQuery()->modify([Constants::PARAM_MAX_ITEMS => (string) $maxItems]);
849 2
        }
850
851
        $responseData = (array) $this->readJson($url);
852
853 2
        return $this->getJsonConverter()->convertRenditions($responseData);
854
    }
855
856
    /**
857 2
     * Moves the specified file-able object from one folder to another.
858 2
     *
859
     * @param string $repositoryId the identifier for the repository
860 2
     * @param string $objectId the identifier for the object. The repository might return a different/new object id
861 2
     * @param string $targetFolderId the identifier for the target folder
862
     * @param string $sourceFolderId the identifier for the source folder
863 2
     * @param ExtensionDataInterface|null $extension
864
     * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code>
865 2
     *     if the repository response was empty
866 1
     */
867 1
    public function moveObject(
868
        $repositoryId,
869 2
        & $objectId,
870
        $targetFolderId,
871 2
        $sourceFolderId,
872
        ExtensionDataInterface $extension = null
873
    ) {
874
        $this->flushCached();
875
876
        $url = $this->getObjectUrl($repositoryId, $objectId);
877
        $url->getQuery()->modify(
878
            [
879
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_MOVE,
880
                Constants::PARAM_TARGET_FOLDER_ID => $targetFolderId,
881
                Constants::PARAM_SOURCE_FOLDER_ID => $sourceFolderId,
882
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
883
            ]
884
        );
885 1
886
        $newObject = $this->getJsonConverter()->convertObject($this->postJson($url));
887
888
        // $objectId was passed by reference. The value is changed here to new object id
889
        $objectId = ($newObject === null) ? null : $newObject->getId();
890
891
        return $newObject;
892 1
    }
893
894 1
    /**
895 1
     * Sets the content stream for the specified document object.
896
     *
897 1
     * @param string $repositoryId The identifier for the repository
898 1
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
899 1
     * @param StreamInterface $contentStream The content stream
900 1
     * @param boolean $overwriteFlag If <code>true</code>, then the repository must replace the existing content stream
901 1
     *      for the object (if any) with the input content stream. If <code>false</code>, then the repository must
902 1
     *      only set the input content stream for the object if the object currently does not have a content stream
903
     *      (default is <code>true</code>)
904 1
     * @param string|null $changeToken The last change token of this object that the client received.
905 1
     *      The repository might return a new change token (default is <code>null</code>)
906
     * @param ExtensionDataInterface|null $extension
907
     * @throws CmisInvalidArgumentException If object id is empty
908 1
     */
909
    public function setContentStream(
910 1
        $repositoryId,
911
        & $objectId,
912
        StreamInterface $contentStream,
913
        $overwriteFlag = true,
914
        & $changeToken = null,
915
        ExtensionDataInterface $extension = null
916
    ) {
917
        if (empty($objectId)) {
918
            throw new CmisInvalidArgumentException('Object id must not be empty!');
919
        }
920
921
        $this->flushCached();
922
923
        $url = $this->getObjectUrl($repositoryId, $objectId);
924
925
        $url->getQuery()->modify(
926
            [
927
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_SET_CONTENT,
928 3
                Constants::PARAM_OVERWRITE_FLAG => $overwriteFlag ? 'true' : 'false',
929
                Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false'
930
            ]
931
        );
932
933 View Code Duplication
        if ($changeToken !== null && !$this->getSession()->get(SessionParameter::OMIT_CHANGE_TOKENS, false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
934
            $url->getQuery()->modify([Constants::PARAM_CHANGE_TOKEN => $changeToken]);
935
        }
936 3
937
        $newObject = $this->getJsonConverter()->convertObject(
938
            (array) $this->postJson($url, ['content' => $contentStream])
939
        );
940 3
941
        // $objectId was passed by reference. The value is changed here to new object id
942 3
        $objectId = null;
943 View Code Duplication
        if ($newObject !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
944 3
            $objectId = $newObject->getId();
945
            $newObjectProperties = $newObject->getProperties()->getProperties();
946 3
            if ($changeToken !== null && count($newObjectProperties) > 0) {
947 3
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
948 3
                // $changeToken was passed by reference. The value is changed here
949 3
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
950 3
            }
951
        }
952 3
    }
953 1
954 1
    /**
955
     * Updates properties of the specified object.
956 3
     *
957 3
     * @param string $repositoryId The identifier for the repository
958
     * @param string $objectId The identifier for the object. The repository might return a different/new object id
959 3
     * @param PropertiesInterface $properties The updated property values that must be applied to the object
960
     * @param string|null $changeToken The last change token of this object that the client received.
961 3
     *      The repository might return a new change token (default is <code>null</code>)
962
     * @param ExtensionDataInterface|null $extension
963
     * @throws CmisInvalidArgumentException If $objectId is empty
964 3
     */
965 3
    public function updateProperties(
966 3
        $repositoryId,
967 3
        & $objectId,
968 3
        PropertiesInterface $properties,
969 2
        & $changeToken = null,
970
        ExtensionDataInterface $extension = null
971 2
    ) {
972 2
        if (empty($objectId)) {
973 3
            throw new CmisInvalidArgumentException('Object id must not be empty!');
974 3
        }
975
976
        $this->flushCached();
977
978
        $url = $this->getObjectUrl($repositoryId, $objectId);
979
980 View Code Duplication
        if ($changeToken !== null && !$this->getSession()->get(SessionParameter::OMIT_CHANGE_TOKENS, false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
981
            $url->getQuery()->modify([Constants::PARAM_CHANGE_TOKEN => $changeToken]);
982
        }
983
984
        $queryArray = $this->convertPropertiesToQueryArray($properties);
985
        $queryArray[Constants::CONTROL_CMISACTION] = Constants::CMISACTION_UPDATE_PROPERTIES;
986
        $queryArray[Constants::PARAM_SUCCINCT] = $this->getSuccinct() ? 'true' : 'false';
987 3
        $newObject = $this->getJsonConverter()->convertObject((array) $this->postJson($url, $queryArray));
988
989
        // $objectId was passed by reference. The value is changed here to new object id
990
        $objectId = null;
991 View Code Duplication
        if ($newObject !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
992
            $objectId = $newObject->getId();
993
            $newObjectProperties = $newObject->getProperties()->getProperties();
994 3
            if ($changeToken !== null && count($newObjectProperties) > 0) {
995
                $newChangeToken = $newObjectProperties[PropertyIds::CHANGE_TOKEN];
996
                // $changeToken was passed by reference. The value is changed here
997
                $changeToken = $newChangeToken === null ? null : $newChangeToken->getFirstValue();
998 3
            }
999
        }
1000 3
    }
1001
1002 3
    /**
1003 1
     * @param string $identifier
1004 1
     * @param mixed $additionalHashValues
1005
     * @return array
1006 3
     */
1007 3
    protected function createCacheKey($identifier, $additionalHashValues)
1008 3
    {
1009 3
        return [
1010 3
            $identifier,
1011
            sha1(is_array($additionalHashValues) ? serialize($additionalHashValues) : $additionalHashValues)
1012
        ];
1013 3
    }
1014 3
1015 3
    /**
1016 3
     * Returns TRUE if an object with cache key $identifier is currently cached.
1017 3
     *
1018 2
     * @param array $identifier
1019
     * @return boolean
1020 2
     */
1021 2
    protected function isCached(array $identifier)
1022 3
    {
1023 3
        return isset($this->objectCache[$identifier[0]][$identifier[1]]);
1024
    }
1025
1026
    /**
1027
     * Gets the cached object with cache key $identifier.
1028
     *
1029
     * @param string $identifier
0 ignored issues
show
Documentation introduced by
Should the type for parameter $identifier not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1030 8
     * @return mixed
1031
     */
1032
    protected function getCached(array $identifier)
1033 8
    {
1034 8
        return $this->objectCache[$identifier[0]][$identifier[1]] ?? null;
1035 8
    }
1036
1037
	/**
1038
     * Gets the cached object with cache key $identifier.
1039
     *
1040
     * @param string $identifier
0 ignored issues
show
Documentation introduced by
Should the type for parameter $identifier not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1041
     * @param mixed $object
1042
     * @return mixed
1043
     */
1044 8
    protected function cache(array $identifier, $object)
1045
    {
1046 8
        $this->objectCache[$identifier[0]][$identifier[1]] = $object;
1047
        return $object;
1048
    }
1049
1050
	/**
1051
	 * Flushes all cached entries. This is implemented as a flush-all with
1052
	 * no way to flush individual entries due to the way CMIS object data
1053
	 * gets returned from CMIS. Two widely different object data sets may
1054
	 * contain a reference to the same item and even with extensive cross
1055
	 * referencing it would be technically unfeasible to selectively clear
1056
	 * or reload an object by identifier. Such flushing would be inevitably
1057
	 * flawed with edge cases of incomplete flushing or become so complex
1058
	 * that it defeats the purpose of caching in the first place.
1059
	 *
1060
	 * Note that cache flushing only happens when modifying the repository
1061
	 * contents - which should limit the negative impact. The cache is also
1062
	 * not persistent and will only affect the current request. As such, it
1063
	 * is implemented to optimise requests where the same object, type,
1064
	 * policy etc. gets accessed multiple times.
1065
	 *
1066
	 * @return void
1067
	 */
1068
	protected function flushCached()
1069
	{
1070 8
		$this->objectCache = [];
1071
	}
1072
}
1073