Completed
Push — master ( 90226b...85c5a1 )
by
unknown
19:31
created

DynamicallyConfiguredMatcherFactoryDecorator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A match() 0 7 1
1
<?php
2
3
/**
4
 * File containing the AbstractMatcherFactory class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\MVC\Symfony\Matcher;
10
11
use eZ\Publish\Core\MVC\ConfigResolverInterface;
12
use eZ\Publish\Core\MVC\Symfony\View\View;
13
14
/**
15
 * Injects dynamic configuration before every matching operation.
16
 */
17
class DynamicallyConfiguredMatcherFactoryDecorator implements MatcherFactoryInterface
18
{
19
    /** @var \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherFactoryInterface|\eZ\Publish\Core\MVC\Symfony\Matcher\ConfigurableMatcherFactoryInterface */
20
    private $innerConfigurableMatcherFactory;
21
22
    /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */
23
    private $configResolver;
24
25
    /** @var string */
26
    private $parameterName;
27
28
    /** @var string|null */
29
    private $namespace;
30
31
    /** @var string|null */
32
    private $scope;
33
34
    public function __construct(
35
        MatcherFactoryInterface $innerConfigurableMatcherFactory,
36
        ConfigResolverInterface $configResolver,
37
        string $parameterName,
38
        ?string $namespace = null,
39
        ?string $scope = null
40
    ) {
41
        $this->innerConfigurableMatcherFactory = $innerConfigurableMatcherFactory;
42
        $this->configResolver = $configResolver;
43
        $this->parameterName = $parameterName;
44
        $this->namespace = $namespace;
45
        $this->scope = $scope;
46
    }
47
48
    public function match(View $view)
49
    {
50
        $matchConfig = $this->configResolver->getParameter($this->parameterName, $this->namespace, $this->scope);
51
        $this->innerConfigurableMatcherFactory->setMatchConfig($matchConfig);
52
53
        return $this->innerConfigurableMatcherFactory->match($view);
54
    }
55
}
56