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 ( 49ac87...0af725 )
by
unknown
09:26 queued 05:36
created

AbstractBrowserBindingService::setDateTimeFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Dkd\PhpCmis\Bindings\Browser;
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\PhpCmis\Bindings\BindingSessionInterface;
14
use Dkd\PhpCmis\Bindings\CmisBindingsHelper;
15
use Dkd\PhpCmis\Bindings\LinkAccessInterface;
16
use Dkd\PhpCmis\Constants;
17
use Dkd\PhpCmis\Data\AclInterface;
18
use Dkd\PhpCmis\Data\PropertiesInterface;
19
use Dkd\PhpCmis\DataObjects\RepositoryInfo;
20
use Dkd\PhpCmis\DataObjects\RepositoryInfoBrowserBinding;
21
use Dkd\PhpCmis\Definitions\TypeDefinitionInterface;
22
use Dkd\PhpCmis\Enum\DateTimeFormat;
23
use Dkd\PhpCmis\Exception\CmisBaseException;
24
use Dkd\PhpCmis\Exception\CmisConnectionException;
25
use Dkd\PhpCmis\Exception\CmisConstraintException;
26
use Dkd\PhpCmis\Exception\CmisInvalidArgumentException;
27
use Dkd\PhpCmis\Exception\CmisNotSupportedException;
28
use Dkd\PhpCmis\Exception\CmisObjectNotFoundException;
29
use Dkd\PhpCmis\Exception\CmisPermissionDeniedException;
30
use Dkd\PhpCmis\Exception\CmisProxyAuthenticationException;
31
use Dkd\PhpCmis\Exception\CmisRuntimeException;
32
use Dkd\PhpCmis\Exception\CmisUnauthorizedException;
33
use Dkd\PhpCmis\SessionParameter;
34
use GuzzleHttp\Client;
35
use GuzzleHttp\Psr7\Response;
36
use GuzzleHttp\Stream\StreamInterface;
37
use GuzzleHttp\Exception\RequestException;
38
use League\Url\Url;
39
40
/**
41
 * Base class for all Browser Binding client services.
42
 */
43
abstract class AbstractBrowserBindingService implements LinkAccessInterface
44
{
45
    /**
46
     * @var BindingSessionInterface
47
     */
48
    protected $session;
49
50
    /**
51
     * @var boolean
52
     */
53
    protected $succinct;
54
55
    /**
56
     * @var CmisBindingsHelper
57
     */
58
    protected $cmisBindingsHelper;
59
60
    /**
61
     * @var DateTimeFormat
62
     */
63
    protected $dateTimeFormat;
64
65
    /**
66
     * @param BindingSessionInterface $session
67
     * @param CmisBindingsHelper|null $cmisBindingsHelper
68
     */
69 168
    public function __construct(BindingSessionInterface $session, $cmisBindingsHelper = null)
70
    {
71 168
        $this->setCmisBindingsHelper($cmisBindingsHelper);
72 168
        $this->setSession($session);
73 168
    }
74
75
    /**
76
     * Set cmis binding helper property
77
     *
78
     * @param CmisBindingsHelper|null $cmisBindingsHelper The cmis binding helper that should be defined.
79
     * If <code>null</code> is given a new instance of CmisBindingsHelper will be created.
80
     */
81 168
    protected function setCmisBindingsHelper($cmisBindingsHelper = null)
82
    {
83 168
        $this->cmisBindingsHelper = ($cmisBindingsHelper === null) ? new CmisBindingsHelper() : $cmisBindingsHelper;
84 168
    }
85
86
    /**
87
     * Get the url for an object
88
     *
89
     * @param string $repositoryId
90
     * @param string $objectId
91
     * @param string|null $selector
92
     * @throws CmisConnectionException
93
     * @throws CmisObjectNotFoundException
94
     * @return Url
95
     */
96 2 View Code Duplication
    protected function getObjectUrl($repositoryId, $objectId, $selector = null)
97
    {
98 2
        $result = $this->getRepositoryUrlCache()->getObjectUrl($repositoryId, $objectId, $selector);
99
100 2
        if ($result === null) {
101 1
            $this->getRepositoriesInternal($repositoryId);
102 1
            $result = $this->getRepositoryUrlCache()->getObjectUrl($repositoryId, $objectId, $selector);
103 1
        }
104
105 2
        if ($result === null) {
106 1
            throw new CmisObjectNotFoundException(
107 1
                sprintf(
108 1
                    'Unknown Object! Repository: "%s" | Object: "%s" | Selector: "%s"',
109 1
                    $repositoryId,
110 1
                    $objectId,
111
                    $selector
112 1
                )
113 1
            );
114
        }
115
116 1
        return $result;
117
    }
118
119
    /**
120
     * Returns the repository URL cache or creates a new cache if it doesn't
121
     * exist.
122
     *
123
     * @return RepositoryUrlCache
124
     */
125 2
    protected function getRepositoryUrlCache()
126
    {
127 2
        $repositoryUrlCache = $this->getSession()->get(SessionParameter::REPOSITORY_URL_CACHE);
128 2
        if ($repositoryUrlCache === null) {
129 1
            $repositoryUrlCache = new RepositoryUrlCache();
130 1
            $this->getSession()->put(SessionParameter::REPOSITORY_URL_CACHE, $repositoryUrlCache);
131 1
        }
132
133 2
        return $repositoryUrlCache;
134
    }
135
136
    /**
137
     * Get current session
138
     *
139
     * @return BindingSessionInterface
140
     */
141 66
    public function getSession()
142
    {
143 66
        return $this->session;
144
    }
145
146
    /**
147
     * Sets the current session.
148
     *
149
     * @param BindingSessionInterface $session
150
     */
151 168
    protected function setSession(BindingSessionInterface $session)
152
    {
153 168
        $this->session = $session;
154 168
        $succinct = $session->get(SessionParameter::BROWSER_SUCCINCT);
155 168
        $this->succinct = ($succinct === null ? true : (boolean) $succinct);
156
157 168
        $this->dateTimeFormat = DateTimeFormat::cast($session->get(SessionParameter::BROWSER_DATETIME_FORMAT));
158 168
    }
159
160
    /**
161
     * Retrieves the the repository info objects.
162
     *
163
     * @param string|null $repositoryId
164
     * @throws CmisConnectionException
165
     * @return RepositoryInfo[] Returns ALL Repository Infos that are available and not just the one requested by id.
166
     */
167 8
    protected function getRepositoriesInternal($repositoryId = null)
168
    {
169 8
        $repositoryUrlCache = $this->getRepositoryUrlCache();
170
171 8
        if ($repositoryId === null) {
172
            // no repository id provided -> get all
173 6
            $url = $repositoryUrlCache->buildUrl($this->getServiceUrl());
174 6
        } else {
175
            // use URL of the specified repository
176 2
            $url = $repositoryUrlCache->getRepositoryUrl($repositoryId, Constants::SELECTOR_REPOSITORY_INFO);
177 2
            if ($url === null) {
178
                // repository infos haven't been fetched yet -> get them all
179 1
                $url = $repositoryUrlCache->buildUrl($this->getServiceUrl());
180 1
            }
181
        }
182
183 8
        $repositoryInfos = array();
184 8
        $result = \json_decode(
185 8
            $this->read($url)->getBody(),
186
            true
187 8
        );
188 8
        if (!is_array($result)) {
189 1
            throw new CmisConnectionException(
190 1
                'Could not fetch repository info! Response is not a valid JSON.',
191
                1416343166
192 1
            );
193
        }
194 7
        foreach ($result as $item) {
195 7
            if (is_array($item)) {
196 6
                $repositoryInfo = $this->getJsonConverter()->convertRepositoryInfo($item);
197
198 6
                if ($repositoryInfo instanceof RepositoryInfoBrowserBinding) {
199 6
                    $id = $repositoryInfo->getId();
200 6
                    $repositoryUrl = $repositoryInfo->getRepositoryUrl();
201 6
                    $rootUrl = $repositoryInfo->getRootUrl();
202
203 6
                    if (empty($id) || empty($repositoryUrl) || empty($rootUrl)) {
204 3
                        throw new CmisConnectionException(
205 3
                            sprintf('Found invalid Repository Info! (id: %s)', $id),
206
                            1415187765
207 3
                        );
208
                    }
209
210 3
                    $this->getRepositoryUrlCache()->addRepository($id, $repositoryUrl, $rootUrl);
211
212 3
                    $repositoryInfos[] = $repositoryInfo;
213 3
                }
214 3
            } else {
215 1
                throw new CmisConnectionException(
216 1
                    sprintf(
217
                        'Found invalid repository info! Value of type "array" was expected'
218 1
                        . 'but value of type "%s" was given.',
219 1
                        gettype($item)
220 1
                    ),
221
                    1415187764
222 1
                );
223
            }
224 3
        }
225
226 3
        return $repositoryInfos;
227
    }
228
229
    /**
230
     * Returns the service URL of this session.
231
     *
232
     * @return string|null
233
     */
234 2
    protected function getServiceUrl()
235
    {
236 2
        $browserUrl = $this->getSession()->get(SessionParameter::BROWSER_URL);
237 2
        if (is_string($browserUrl)) {
238 1
            return $browserUrl;
239
        }
240
241 1
        return null;
242
    }
243
244
    /**
245
     * Do a get request for the given url
246
     *
247
     * @param Url $url
248
     * @return Response
249
     * @throws CmisBaseException an more specific exception of this type could be thrown. For more details see
250
     * @see AbstractBrowserBindingService::convertStatusCode()
251
     */
252 3
    protected function read(Url $url)
253
    {
254
        /** @var Response $response */
255
        try {
256 3
            $response = $this->getHttpInvoker()->get((string) $url);
257 3
        } catch (RequestException $exception) {
258 2
            $code = 0;
259 2
            $message = null;
260 2
            if ($exception->getResponse()) {
261 2
                $code = $exception->getResponse()->getStatusCode();
262 2
                $message = $exception->getResponse()->getBody();
263 2
            }
264 2
            throw $this->convertStatusCode(
265 2
                $code,
266 2
                (string) $message,
267
                $exception
268 2
            );
269
        }
270
271 1
        return $response;
272
    }
273
274
    /**
275
     * Get a HTTP Invoker instance
276
     *
277
     * @return Client
278
     */
279 4
    protected function getHttpInvoker()
280
    {
281
        /** @var Client $invoker */
282 4
        $invoker = $this->cmisBindingsHelper->getHttpInvoker($this->getSession());
283
284 4
        return $invoker;
285
    }
286
287
    /**
288
     * Converts an error message or a HTTP status code into an Exception.
289
     *
290
     * @see http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html#x1-551021r549
291
     *
292
     * @param integer $code
293
     * @param string $message
294
     * @param null|\Exception $exception
295
     * @return CmisBaseException
296
     */
297 26
    protected function convertStatusCode($code, $message, \Exception $exception = null)
298
    {
299 26
        $messageData = json_decode($message, true);
300
301 26
        if (is_array($messageData) && !empty($messageData[JSONConstants::ERROR_EXCEPTION])) {
302 13
            $jsonError = $messageData[JSONConstants::ERROR_EXCEPTION];
303
304 13
            if (!empty($messageData[JSONConstants::ERROR_MESSAGE])
305 13
                && is_string($messageData[JSONConstants::ERROR_MESSAGE])
306 13
            ) {
307 13
                $message = $messageData[JSONConstants::ERROR_MESSAGE];
308 13
            }
309
310 13
            $exceptionName = '\\Dkd\\PhpCmis\\Exception\\Cmis' . ucfirst($jsonError) . 'Exception';
311
312 13
            if (class_exists($exceptionName)) {
313 12
                return new $exceptionName($message, null, $exception);
314
            }
315 1
        }
316
317 14
        if (empty($message) && $exception !== null) {
318
            $message = $exception->getMessage();
319
        }
320
321
        // fall back to status code
322
        switch ($code) {
323 14
            case 301:
324 14
            case 302:
325 14
            case 303:
326 14
            case 307:
327 4
                return new CmisConnectionException(
328 4
                    'Redirects are not supported (HTTP status code ' . $code . '): ' . $message,
329 4
                    null,
330
                    $exception
331 4
                );
332 10
            case 400:
333 1
                return new CmisInvalidArgumentException($message, null, $exception);
334 9
            case 401:
335 1
                return new CmisUnauthorizedException($message, null, $exception);
336 8
            case 403:
337 1
                return new CmisPermissionDeniedException($message, null, $exception);
338 7
            case 404:
339 1
                return new CmisObjectNotFoundException($message, null, $exception);
340 6
            case 405:
341 1
                return new CmisNotSupportedException($message, null, $exception);
342 5
            case 407:
343 1
                return new CmisProxyAuthenticationException($message, null, $exception);
344 4
            case 409:
345 1
                return new CmisConstraintException($message, null, $exception);
346 3
            default:
347 3
                return new CmisRuntimeException($message, null, $exception);
348 3
        }
349
    }
350
351
    // ---- helpers ----
352
353
    /**
354
     * Returns JSON Converter instance
355
     *
356
     * @return \Dkd\PhpCmis\Converter\JsonConverter
357
     */
358 65
    protected function getJsonConverter()
359
    {
360 65
        return $this->cmisBindingsHelper->getJsonConverter($this->getSession());
361
    }
362
363
    /**
364
     * Generate url for a given path of a given repository.
365
     *
366
     * @param string $repositoryId
367
     * @param string $path
368
     * @param string|null $selector
369
     * @throws CmisConnectionException
370
     * @throws CmisObjectNotFoundException
371
     * @return Url
372
     */
373 2 View Code Duplication
    protected function getPathUrl($repositoryId, $path, $selector = null)
374
    {
375 2
        $result = $this->getRepositoryUrlCache()->getPathUrl($repositoryId, $path, $selector);
376
377 2
        if ($result === null) {
378 1
            $this->getRepositoriesInternal($repositoryId);
379 1
            $result = $this->getRepositoryUrlCache()->getPathUrl($repositoryId, $path, $selector);
380 1
        }
381
382 2
        if ($result === null) {
383 1
            throw new CmisObjectNotFoundException(
384 1
                sprintf(
385 1
                    'Unknown path! Repository: "%s" | Path: "%s" | Selector: "%s"',
386 1
                    $repositoryId,
387 1
                    $path,
388
                    $selector
389 1
                )
390 1
            );
391
        }
392
393 1
        return $result;
394
    }
395
396
// ---- URL ----
397
398
    /**
399
     * Get if succinct mode is used
400
     *
401
     * @return boolean
402
     */
403 46
    protected function getSuccinct()
404
    {
405 46
        return $this->succinct;
406
    }
407
408
    /**
409
     * Performs a POST on an URL, checks the response code and returns the
410
     * result.
411
     *
412
     * @param Url $url Request url
413
     * @param resource|string|StreamInterface|array $content Entity body data or an array for POST fields and files
414
     * @param array $headers Additional header options
415
     * @return Response
416
     * @throws CmisBaseException an more specific exception of this type could be thrown. For more details see
417
     * @see AbstractBrowserBindingService::convertStatusCode()
418
     */
419 2
    protected function post(Url $url, $content = array(), array $headers = array())
420
    {
421 2
        $headers['form_params'] = $content;
422
423
        try {
424
            /** @var Response $response */
425 2
            $response = $this->getHttpInvoker()->post((string) $url, $headers);
426 2
        } catch (RequestException $exception) {
427 1
            throw $this->convertStatusCode(
428 1
                $exception->getResponse()->getStatusCode(),
429 1
                (string) $exception->getResponse()->getBody(),
430
                $exception
431 1
            );
432
        }
433
434 1
        return $response;
435
    }
436
437
    /**
438
     * Retrieves a type definition.
439
     *
440
     * @param string $repositoryId
441
     * @param string $typeId
442
     * @return TypeDefinitionInterface|null
443
     * @throws CmisInvalidArgumentException if repository id or type id is <code>null</code>
444
     */
445 3
    protected function getTypeDefinitionInternal($repositoryId, $typeId)
446
    {
447 3
        if (empty($repositoryId)) {
448 1
            throw new CmisInvalidArgumentException('Repository id must not be empty!');
449
        }
450
451 2
        if (empty($typeId)) {
452 1
            throw new CmisInvalidArgumentException('Type id must not be empty!');
453
        }
454
455
        // build URL
456 1
        $url = $this->getRepositoryUrl($repositoryId, Constants::SELECTOR_TYPE_DEFINITION);
457 1
        $url->getQuery()->modify(array(Constants::PARAM_TYPE_ID => $typeId));
458
459 1
        return $this->getJsonConverter()->convertTypeDefinition(
460 1
            (array) \json_decode(
461 1
                $this->read($url)->getBody(),
462
                true
463 1
            )
464 1
        );
465
    }
466
467
    /**
468
     * Get url for a repository
469
     *
470
     * @param string $repositoryId
471
     * @param string|null $selector
472
     * @throws CmisConnectionException
473
     * @throws CmisObjectNotFoundException
474
     * @return Url
475
     */
476 2 View Code Duplication
    protected function getRepositoryUrl($repositoryId, $selector = null)
477
    {
478 2
        $result = $this->getRepositoryUrlCache()->getRepositoryUrl($repositoryId, $selector);
479
480 2
        if ($result === null) {
481 1
            $this->getRepositoriesInternal($repositoryId);
482 1
            $result = $this->getRepositoryUrlCache()->getRepositoryUrl($repositoryId, $selector);
483 1
        }
484
485 2
        if ($result === null) {
486 1
            throw new CmisObjectNotFoundException(
487 1
                sprintf(
488 1
                    'Unknown repository! Repository: "%s" | Selector: "%s"',
489 1
                    $repositoryId,
490
                    $selector
491 1
                )
492 1
            );
493
        }
494
495 1
        return $result;
496
    }
497
498
    /**
499
     * Converts a Properties list into an array that can be used for the CMIS request.
500
     *
501
     * @param PropertiesInterface $properties
502
     * @return array Example <code>
503
     * array('propertyId' => array(0 => 'myId'), 'propertyValue' => array(0 => 'valueOfMyId'))
504
     * </code>
505
     */
506 13
    protected function convertPropertiesToQueryArray(PropertiesInterface $properties)
507
    {
508 13
        $propertiesArray = array();
509
510 13
        $propertyCounter = 0;
511 13
        $propertiesArray[Constants::CONTROL_PROP_ID] = array();
512 13
        $propertiesArray[Constants::CONTROL_PROP_VALUE] = array();
513 13
        foreach ($properties->getProperties() as $property) {
514 13
            $propertiesArray[Constants::CONTROL_PROP_ID][$propertyCounter] = $property->getId();
515
516 13
            $propertyValues = $property->getValues();
517
518 13
            if (count($propertyValues) === 1) {
519 13
                $propertiesArray[Constants::CONTROL_PROP_VALUE][$propertyCounter] =
520 13
                    $this->convertPropertyValueToSimpleType(
521 13
                        $property->getFirstValue()
522 13
                    );
523 13
            } elseif (count($propertyValues) > 1) {
524 1
                $propertyValueCounter = 0;
525 1
                $propertiesArray[Constants::CONTROL_PROP_VALUE][$propertyCounter] = array();
526 1
                foreach ($propertyValues as $propertyValue) {
527 1
                    $propertiesArray[Constants::CONTROL_PROP_VALUE][$propertyCounter][$propertyValueCounter] =
528 1
                        $this->convertPropertyValueToSimpleType(
529
                            $propertyValue
530 1
                        );
531 1
                    $propertyValueCounter ++;
532 1
                }
533 1
            }
534
535 13
            $propertyCounter ++;
536 13
        }
537
538 13
        return $propertiesArray;
539
    }
540
541
    /**
542
     * Converts values to a format that can be used for the CMIS Browser binding request.
543
     *
544
     * @param mixed $value
545
     * @return mixed
546
     */
547 13
    protected function convertPropertyValueToSimpleType($value)
548
    {
549 13
        if ($value instanceof \DateTime) {
550
            // CMIS expects a timestamp in milliseconds
551 1
            $value = $value->getTimestamp() * 1000;
552 13
        } elseif (is_bool($value)) {
553
			// Booleans must be represented in string form since request will fail if cast to integer
554 1
			$value = $value ? 'true' : 'false';
555 1
		}
556
557 13
        return $value;
558
    }
559
560
    /**
561
     * Converts a Access Control list into an array that can be used for the CMIS request
562
     *
563
     * @param AclInterface $acl
564
     * @param string $principalControl one of principal ace constants
565
     * CONTROL_ADD_ACE_PRINCIPAL or CONTROL_REMOVE_ACE_PRINCIPAL
566
     * @param string $permissionControl one of permission ace constants
567
     * CONTROL_REMOVE_ACE_PRINCIPAL or CONTROL_REMOVE_ACE_PERMISSION
568
     * @return array Example <code>
569
     * array('addACEPrincipal' => array(0 => 'principalId'),
570
     *       'addACEPermission' => array(0 => array(0 => 'permissonValue')))
571
     * </code>
572
     */
573 7
    protected function convertAclToQueryArray(AclInterface $acl, $principalControl, $permissionControl)
574
    {
575 7
        $acesArray = array();
576 7
        $principalCounter = 0;
577
578 7
        foreach ($acl->getAces() as $ace) {
579 7
            $permissions = $ace->getPermissions();
580 7
            if ($ace->getPrincipal() !== null && $ace->getPrincipal()->getId() && !empty($permissions)) {
581 7
                $acesArray[$principalControl][$principalCounter] = $ace->getPrincipal()->getId();
582 7
                $permissionCounter = 0;
583 7
                $acesArray[$permissionControl][$principalCounter] = array();
584
585 7
                foreach ($permissions as $permission) {
586 7
                    $acesArray[$permissionControl][$principalCounter][$permissionCounter] = $permission;
587 7
                    $permissionCounter ++;
588 7
                }
589
590 7
                $principalCounter ++;
591 7
            }
592 7
        }
593
594 7
        return $acesArray;
595
    }
596
597
    /**
598
     * Converts a policies array into an array that can be used for the CMIS request
599
     *
600
     * @param string[] $policies A list of policy string representations
601
     * @return array
602
     */
603 10
    protected function convertPolicyIdArrayToQueryArray(array $policies)
604
    {
605 10
        $policiesArray = array();
606 10
        $policyCounter = 0;
607
608 10
        foreach ($policies as $policy) {
609 6
            $policiesArray[Constants::CONTROL_POLICY][$policyCounter] = (string) $policy;
610 6
            $policyCounter ++;
611 10
        }
612
613 10
        return $policiesArray;
614
    }
615
616
    /**
617
     * Returns the date time format
618
     *
619
     * @return DateTimeFormat
620
     */
621 32
    public function getDateTimeFormat()
622
    {
623 32
        return $this->dateTimeFormat;
624
    }
625
626
    /**
627
     * Sets the date time format
628
     *
629
     * @param DateTimeFormat $dateTimeFormat
630
     */
631 1
    public function setDateTimeFormat(DateTimeFormat $dateTimeFormat)
632
    {
633 1
        $this->dateTimeFormat = $dateTimeFormat;
634 1
    }
635
636
    /**
637
     * Appends policies parameters to url
638
     *
639
     * @param Url $url
640
     * @param string[] $policies A list of policy IDs that must be applied to the newly created document object
641
     */
642
    protected function appendPoliciesToUrl(Url $url, array $policies)
643
    {
644
        if (!empty($policies)) {
645
            $url->getQuery()->modify($this->convertPolicyIdArrayToQueryArray($policies));
646
        }
647
    }
648
649
    /**
650
     * Appends addAces parameters to url
651
     *
652
     * @param Url $url
653
     * @param AclInterface|null $addAces A list of ACEs
654
     */
655 View Code Duplication
    protected function appendAddAcesToUrl(Url $url, AclInterface $addAces = null)
656
    {
657
        if ($addAces !== null) {
658
            $url->getQuery()->modify(
659
                $this->convertAclToQueryArray(
660
                    $addAces,
661
                    Constants::CONTROL_ADD_ACE_PRINCIPAL,
662
                    Constants::CONTROL_ADD_ACE_PERMISSION
663
                )
664
            );
665
        }
666
    }
667
668
    /**
669
     * Appends removeAces parameters to url
670
     *
671
     * @param Url $url
672
     * @param AclInterface|null $removeAces A list of ACEs
673
     */
674 View Code Duplication
    protected function appendRemoveAcesToUrl(Url $url, AclInterface $removeAces = null)
675
    {
676
        if ($removeAces !== null) {
677
            $url->getQuery()->modify(
678
                $this->convertAclToQueryArray(
679
                    $removeAces,
680
                    Constants::CONTROL_REMOVE_ACE_PRINCIPAL,
681
                    Constants::CONTROL_REMOVE_ACE_PERMISSION
682
                )
683
            );
684
        }
685
    }
686
687
    /**
688
     * Gets the content link from the cache if it is there or loads it into the
689
     * cache if it is not there.
690
     *
691
     * @param string $repositoryId
692
     * @param string $documentId
693
     * @return string|null
694
     */
695
    public function loadContentLink($repositoryId, $documentId)
696
    {
697
        $result = $this->getRepositoryUrlCache()->getObjectUrl($repositoryId, $documentId, Constants::SELECTOR_CONTENT);
698
        return $result === null ? null : (string) $result;
699
    }
700
701
    /**
702
     * Gets a rendition content link from the cache if it is there or loads it
703
     * into the cache if it is not there.
704
     *
705
     * @param string $repositoryId
706
     * @param string $documentId
707
     * @param string $streamId
708
     * @return string|null
709
     */
710
    public function loadRenditionContentLink($repositoryId, $documentId, $streamId)
711
    {
712
        $result = $this->getRepositoryUrlCache()->getObjectUrl($repositoryId, $documentId, Constants::SELECTOR_CONTENT);
713
        if ($result !== null) {
714
            $result->getQuery()->modify(array(Constants::PARAM_STREAM_ID => $streamId));
715
            $result = (string) $result;
716
        }
717
        return $result;
718
    }
719
}
720