| @@ 13-46 (lines=34) @@ | ||
| 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 | ||
| @@ 13-47 (lines=35) @@ | ||
| 10 | ||
| 11 | use eZ\Publish\Core\Base\Exceptions\NotFoundException; |
|
| 12 | ||
| 13 | final class SiteAccessMatcherRegistry |
|
| 14 | { |
|
| 15 | /** @var \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher[] */ |
|
| 16 | private $matchers; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @param \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher[] $matchers |
|
| 20 | */ |
|
| 21 | public function __construct(array $matchers = []) |
|
| 22 | { |
|
| 23 | $this->matchers = $matchers; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function setMatcher(string $identifier, Matcher $matcher): void |
|
| 27 | { |
|
| 28 | $this->matchers[$identifier] = $matcher; |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
|
| 33 | */ |
|
| 34 | public function getMatcher(string $identifier): Matcher |
|
| 35 | { |
|
| 36 | if (!$this->hasMatcher($identifier)) { |
|
| 37 | throw new NotFoundException('SiteAccess Matcher', $identifier); |
|
| 38 | } |
|
| 39 | ||
| 40 | return $this->matchers[$identifier]; |
|
| 41 | } |
|
| 42 | ||
| 43 | public function hasMatcher(string $identifier): bool |
|
| 44 | { |
|
| 45 | return isset($this->matchers[$identifier]); |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||