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

AbstractWidget   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 3 1
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