Completed
Push — dynamic_siteaccesses ( 16c7ff )
by
unknown
20:23
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 AppendIterator;
12
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
13
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessProviderInterface;
14
use eZ\Publish\Core\MVC\Symfony\SiteAccessList;
15
16
final class ChainSiteAccessProvider implements SiteAccessProviderInterface
17
{
18
    /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessProviderInterface[] */
19
    private $providers;
20
21
    public function __construct(iterable $providers)
22
    {
23
        $this->providers = $providers;
24
    }
25
26
    public function getSiteAccesses(): \Iterator
27
    {
28
        $iterator = new AppendIterator();
29
        foreach($this->providers as $provider) {
30
            $iterator->append($provider->getSiteAccesses());
31
        }
32
        return $iterator;
33
    }
34
35
    public function isDefined(string $name): bool
36
    {
37
        foreach ($this->providers as $provider) {
38
            if ($provider->isDefined($name)) {
39
                return true;
40
            }
41
        }
42
43
        return false;
44
    }
45
46 View Code Duplication
    public function getSiteAccess(string $name): SiteAccess
47
    {
48
        foreach ($this->providers as $provider) {
49
            if ($provider->isDefined($name)) {
50
                return $provider->getSiteAccess($name);
51
            }
52
        }
53
54
        throw new \RuntimeException("Undefined siteaccess: $name");
55
    }
56
}
57