Completed
Push — ezp-31079-twig-variables ( 1c4141 )
by
unknown
14:24
created

GenericVariableProviderRegistry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setTwigVariableProvider() 0 4 1
A getTwigVariableProvider() 0 4 1
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 Traversable;
12
13
final class GenericVariableProviderRegistry implements VariableProviderRegistry
14
{
15
    /** @var \eZ\Publish\Core\MVC\Symfony\View\VariableProvider[] */
16
    private $twigVariableProviders;
17
18
    public function __construct(Traversable $twigVariableProviders)
19
    {
20
        foreach ($twigVariableProviders as $twigVariableProvider) {
21
            $this->setTwigVariableProvider($twigVariableProvider);
22
        }
23
    }
24
25
    public function setTwigVariableProvider(VariableProvider $twigVariableProvider): void
26
    {
27
        $this->twigVariableProviders[$twigVariableProvider->getIdentifier()] = $twigVariableProvider;
28
    }
29
30
    public function getTwigVariableProvider(string $identifier): ?VariableProvider
31
    {
32
        return $this->twigVariableProviders[$identifier] ?? null;
33
    }
34
35
    public function hasTwigVariableProvider(string $identifier): bool
36
    {
37
        return isset($this->twigVariableProviders[$identifier]);
38
    }
39
}
40