Completed
Push — ezp25003-trash_subitems_count_... ( cf1e00...cc3aa3 )
by André
34:07
created

Configured::buildContentView()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the Configured 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
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\MVC\Symfony\View\Provider;
12
13
use eZ\Publish\Core\MVC\Symfony\Matcher\MatcherFactoryInterface;
14
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
15
use eZ\Publish\Core\MVC\Symfony\View\View;
16
use eZ\Publish\Core\MVC\Symfony\View\ViewProvider;
17
use Symfony\Component\HttpKernel\Controller\ControllerReference;
18
19
/**
20
 * Base for View Providers.
21
 */
22
class Configured implements ViewProvider
23
{
24
    /**
25
     * @var \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherFactoryInterface
26
     */
27
    protected $matcherFactory;
28
29
    /**
30
     * @param \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherFactoryInterface $matcherFactory
31
     */
32
    public function __construct(MatcherFactoryInterface $matcherFactory)
33
    {
34
        $this->matcherFactory = $matcherFactory;
35
    }
36
37
    public function getView(View $view)
38
    {
39
        if (($configHash = $this->matcherFactory->match($view)) === null) {
40
            return null;
41
        }
42
43
        return $this->buildContentView($configHash);
44
    }
45
46
    /**
47
     * Builds a ContentView object from $viewConfig.
48
     *
49
     * @param array $viewConfig
50
     *
51
     * @return ContentView
52
     */
53
    protected function buildContentView(array $viewConfig)
54
    {
55
        $view = new ContentView();
56
        $view->setConfigHash($viewConfig);
57
        if (isset($viewConfig['template'])) {
58
            $view->setTemplateIdentifier($viewConfig['template']);
59
        }
60
        if (isset($viewConfig['controller'])) {
61
            $view->setControllerReference(new ControllerReference($viewConfig['controller']));
62
        }
63
64
        return $view;
65
    }
66
}
67