Completed
Push — master ( 17dfd9...4d8e99 )
by Maxim
02:28
created

AbstractWidget::__construct()   A

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\ViewInterface;
7
8
abstract class AbstractWidget
9
{
10
11
    /**
12
     * @var ContainerInterface
13
     */
14
    protected $container;
15
    /**
16
     * @var ViewInterface
17
     */
18
    protected $view;
19
20
    /**
21
     * @param ContainerInterface $container
22
     */
23
    public function __construct(ContainerInterface $container)
24
    {
25
        $this->container = $container;
26
        $this->view = $this->container->get(ViewInterface::class);
27
    }
28
29
    /**
30
     * @param array $params
31
     * @return string
32
     */
33
    abstract public function run(array $params = []): string;
34
35
    /**
36
     * @param string $templatePath
37
     * @param array $vars
38
     *
39
     * @return string
40
     * @throws \Exception
41
     */
42
    protected function render(string $templatePath, array $vars = []): string
43
    {
44
        return $this->view->layout()->render($templatePath, $vars);
45
    }
46
}
47