Completed
Pull Request — master (#14)
by Flo
02:30
created

AbstractViewHelper::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Class AbstractViewHelper
4
 *
5
 * @method  __invoke()
6
 * @package Faulancer\View
7
 * @author  Florian Knapp <[email protected]>
8
 */
9
namespace Faulancer\View;
10
11
use Faulancer\Exception\ConstantMissingException;
12
use Faulancer\Service\Config;
13
use Faulancer\ServiceLocator\ServiceLocator;
14
15
/**
16
 * Class AbstractViewHelper
17
 */
18
abstract class AbstractViewHelper
19
{
20
21
    /**
22
     * Render a view with given template and variables
23
     * @param  string $template
24
     * @param  array  $variables
25
     * @return string
26
     * @throws ConstantMissingException
27
     */
28
    protected function renderView($template = '', array $variables = []) :string
29
    {
30
        /** @var Config $config */
31
        $config = $this->getServiceLocator()->get(Config::class);
32
33
        $templatePath = $config->get('viewsRoot') . '/helper';
34
35
        return (new ViewController())->setTemplate($templatePath . $template)->setVariables($variables)->render();
36
    }
37
38
    /**
39
     * Get instance of service locator
40
     * @return ServiceLocator
41
     */
42
    public function getServiceLocator() :ServiceLocator
43
    {
44
        return ServiceLocator::instance();
45
    }
46
47
}