Completed
Push — ezp-30882-thumbnail-strategy-i... ( b3e424...83a23b )
by
unknown
13:58
created

getTwigVariableProvider()   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\View;
10
11
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
12
use Traversable;
13
use eZ\Publish\SPI\MVC\View\VariableProvider;
14
15
final class GenericVariableProviderRegistry implements VariableProviderRegistry
16
{
17
    /** @var \eZ\Publish\SPI\MVC\View\VariableProvider[] */
18
    private $twigVariableProviders;
19
20
    public function __construct(Traversable $twigVariableProviders)
21
    {
22
        foreach ($twigVariableProviders as $twigVariableProvider) {
23
            $this->setTwigVariableProvider($twigVariableProvider);
24
        }
25
    }
26
27
    public function setTwigVariableProvider(VariableProvider $twigVariableProvider): void
28
    {
29
        $this->twigVariableProviders[$twigVariableProvider->getIdentifier()] = $twigVariableProvider;
30
    }
31
32
    public function getTwigVariableProvider(string $identifier): VariableProvider
33
    {
34
        if ($this->hasTwigVariableProvider($identifier)) {
35
            return $this->twigVariableProviders[$identifier];
36
        }
37
38
        throw new NotFoundException(VariableProvider::class, $identifier);
39
    }
40
41
    public function hasTwigVariableProvider(string $identifier): bool
42
    {
43
        return isset($this->twigVariableProviders[$identifier]);
44
    }
45
}
46