Completed
Push — master ( ca8025...177d87 )
by Łukasz
14:26
created

ViewMatcherRegistry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
declare(strict_types=1);
7
8
namespace eZ\Bundle\EzPublishCoreBundle\Matcher;
9
10
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
11
use eZ\Publish\Core\MVC\Symfony\Matcher\MatcherInterface;
12
13
final class ViewMatcherRegistry
14
{
15
    /** @var \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherInterface[] */
16
    private $matchers;
17
18
    /**
19
     * @param \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherInterface[] $matchers
20
     */
21
    public function __construct(array $matchers = [])
22
    {
23
        $this->matchers = $matchers;
24
    }
25
26
    public function setMatcher(string $matcherIdentifier, MatcherInterface $matcher): void
27
    {
28
        $this->matchers[$matcherIdentifier] = $matcher;
29
    }
30
31
    /**
32
     * @param string $matcherIdentifier
33
     *
34
     * @return \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MatcherInterface
35
     *
36
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
37
     */
38
    public function getMatcher(string $matcherIdentifier): MatcherInterface
39
    {
40
        if (!isset($this->matchers[$matcherIdentifier])) {
41
            throw new NotFoundException('Matcher', $matcherIdentifier);
42
        }
43
44
        return $this->matchers[$matcherIdentifier];
45
    }
46
}
47