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

GenericVariableProviderRegistry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setTwigVariableProvider() 0 4 1
A getTwigVariableProvider() 0 8 2
A hasTwigVariableProvider() 0 4 1
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