-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAuthorization.php
41 lines (34 loc) · 991 Bytes
/
Authorization.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);
namespace Opengento\Document\Model\DocumentType;
use Opengento\Document\Model\Config\Source\ReadOnlyDocumentTypes;
use function array_column;
use function in_array;
final class Authorization implements AuthorizationInterface
{
/**
* @var ReadOnlyDocumentTypes
*/
private $readOnlyDocTypes;
/**
* @var string[]|null
*/
private $readOnly;
public function __construct(
ReadOnlyDocumentTypes $readOnlyDocTypes
) {
$this->readOnlyDocTypes = $readOnlyDocTypes;
}
public function isReadonly(string $code): bool
{
return in_array($code, $this->resolveReadOnlyCodes(), true);
}
private function resolveReadOnlyCodes(): array
{
return $this->readOnly ?? $this->readOnly = array_column($this->readOnlyDocTypes->toOptionArray(), 'value');
}
}