Completed
Push — test-EZP-26707-issearchable-fu... ( 774d65...d743e2 )
by
unknown
24:59
created

Configured::buildContentView()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 16
rs 8.8571
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
        if (isset($viewConfig['params']) && is_array($viewConfig['params'])) {
64
            $view->addParameters($viewConfig['params']);
65
        }
66
67
        return $view;
68
    }
69
}
70