AbstractWidget::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\mvc\widget;
4
5
use WebComplete\core\utils\container\ContainerInterface;
6
use WebComplete\mvc\view\View;
7
use WebComplete\mvc\view\ViewInterface;
8
9
abstract class AbstractWidget
10
{
11
12
    /**
13
     * @var ContainerInterface
14
     */
15
    protected $container;
16
    /**
17
     * @var ViewInterface
18
     */
19
    protected $view;
20
21
    /**
22
     * @param ContainerInterface $container
23
     */
24
    public function __construct(ContainerInterface $container)
25
    {
26
        $this->container = $container;
27
        $this->view = $this->container->get(View::class);
28
    }
29
30
    /**
31
     * @param array $params
32
     * @return string
33
     */
34
    abstract public function run(array $params = []): string;
35
36
    /**
37
     * @param string $templatePath
38
     * @param array $vars
39
     *
40
     * @return string
41
     * @throws \Exception
42
     */
43
    protected function render(string $templatePath, array $vars = []): string
44
    {
45
        return $this->view->layout()->render($templatePath, $vars);
46
    }
47
}
48