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

ChainSiteAccessProvider::isDefined()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 10
rs 9.9332
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
final class ChainSiteAccessProvider implements SiteAccessProviderInterface
17
{
18
    /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessProviderInterface[] */
19
    private $providers;
20
21
    /**
22
     * @param \eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessProviderInterface[] $providers
23
     */
24
    public function __construct(iterable $providers = [])
25
    {
26
        $this->providers = $providers;
27
    }
28
29
    public function getSiteAccesses(): Traversable
30
    {
31
        foreach ($this->providers as $provider) {
32
            foreach ($provider->getSiteAccesses() as $siteAccess) {
33
                yield $siteAccess;
34
            }
35
        }
36
37
        yield from [];
38
    }
39
40
    public function isDefined(string $name): bool
41
    {
42
        foreach ($this->providers as $provider) {
43
            if ($provider->isDefined($name)) {
44
                return true;
45
            }
46
        }
47
48
        return false;
49
    }
50
51
    /**
52
     * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
53
     */
54
    public function getSiteAccess(string $name): SiteAccess
55
    {
56
        foreach ($this->providers as $provider) {
57
            if ($provider->isDefined($name)) {
58
                return $provider->getSiteAccess($name);
59
            }
60
        }
61
62
        throw new NotFoundException('Site Access', $name);
63
    }
64
}
65