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

TemplatingWidgetHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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