Completed
Push — master ( 11971b...eeafb3 )
by Nate
01:16
created

Template   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 46
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 13 1
A renderTemplate() 0 7 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\views;
10
11
use Craft;
12
use craft\web\View;
13
use yii\base\BaseObject;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 2.0.0
18
 */
19
class Template extends BaseObject implements ViewInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    public $mode = View::TEMPLATE_MODE_CP;
25
26
    /**
27
     * @var string
28
     */
29
    public $template = '';
30
31
    /**
32
     * @param array $params
33
     * @return string
34
     * @throws \Twig_Error_Loader
35
     * @throws \yii\base\Exception
36
     */
37
    public function render(array $params = []): string
38
    {
39
        $view = Craft::$app->getView();
40
41
        $currentMode = $view->getTemplateMode();
42
        $view->setTemplateMode($this->mode);
43
44
        $html = $this->renderTemplate($params);
45
46
        $view->setTemplateMode($currentMode);
47
48
        return $html;
49
    }
50
51
    /**
52
     * @param array $params
53
     * @return string
54
     * @throws \Twig_Error_Loader
55
     * @throws \yii\base\Exception
56
     */
57
    protected function renderTemplate(array $params = []): string
58
    {
59
        return Craft::$app->getView()->renderTemplate(
60
            $this->template,
61
            $params
62
        );
63
    }
64
}
65