Completed
Push — ezp_30981_content_info_proxy ( a78a98...0757d2 )
by
unknown
15:21
created

StaticSiteAccessProvider::getSiteAccess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\MVC\Symfony\SiteAccess\Provider;
10
11
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
12
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
13
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessProviderInterface;
14
use Traversable;
15
16
/**
17
 * @internal For internal use only, do not rely on this class.
18
 *           Be aware this should be regarded as experimental feature.
19
 *           As in, method signatures and behavior might change in the future.
20
 */
21
final class StaticSiteAccessProvider implements SiteAccessProviderInterface
22
{
23
    /** @var string[] */
24
    private $siteAccessList;
25
26
    /**
27
     * @param string[] $siteAccessList
28
     */
29
    public function __construct(
30
        array $siteAccessList
31
    ) {
32
        $this->siteAccessList = $siteAccessList;
33
    }
34
35
    public function getSiteAccesses(): Traversable
36
    {
37
        foreach ($this->siteAccessList as $name) {
38
            yield new SiteAccess($name, SiteAccess::DEFAULT_MATCHING_TYPE, null, self::class);
39
        }
40
41
        yield from [];
42
    }
43
44
    public function isDefined(string $name): bool
45
    {
46
        return \in_array($name, $this->siteAccessList, true);
47
    }
48
49
    public function getSiteAccess(string $name): SiteAccess
50
    {
51
        if ($this->isDefined($name)) {
52
            return new SiteAccess($name, SiteAccess::DEFAULT_MATCHING_TYPE, null, self::class);
53
        }
54
55
        throw new NotFoundException('Site Access', $name);
56
    }
57
}
58