Completed
Push — master ( fecb59...e32f72 )
by Paweł
29:36
created

TemplatingWidgetHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplating() 0 4 1
A __construct() 0 6 1
A renderTemplate() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Template Engine Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\TemplateEngineBundle\Widget;
16
17
use SWP\Component\TemplatesSystem\Gimme\Model\WidgetModelInterface;
18
use SWP\Component\TemplatesSystem\Gimme\Widget\AbstractWidgetHandler;
19
use Symfony\Component\Templating\EngineInterface;
20
21
abstract class TemplatingWidgetHandler extends AbstractWidgetHandler
22
{
23
    /**
24
     * @var EngineInterface
25
     */
26
    protected $templating;
27
28
    /**
29
     * @return EngineInterface
30
     */
31 1
    public function getTemplating()
32
    {
33 1
        return $this->templating;
34
    }
35
36 1
    public function __construct(WidgetModelInterface $widgetModel, EngineInterface $templating)
37
    {
38 1
        parent::__construct($widgetModel);
39
40 1
        $this->templating = $templating;
41 1
    }
42
43
    /**
44
     * Render given template with given parameters.
45
     *
46
     * @param string $templateName
47
     * @param array  $parameters
48
     *
49
     * @return string
50
     */
51 1
    protected function renderTemplate($templateName, $parameters = null)
52
    {
53 1
        if (null === $parameters) {
54 1
            $parameters = $this->getAllParametersWithValue();
55
        }
56
57 1
        return $this->getTemplating()->render('widgets/'.$templateName, $parameters);
58
    }
59
}
60