SmartyEngine::renderFromStringTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace ntentan\honam\engines;
4
5
6
use ntentan\honam\engines\smarty\Core;
7
8
/**
9
 * Description of Mustache
10
 *
11
 * @author ekow
12
 */
13
class SmartyEngine extends AbstractEngine
14
{
15
    private $smarty;
16
17
    public function __construct(Core $smarty)
18
    {
19
        $this->smarty = $smarty;
20
    }
21
22
    /**
23
     * Passes the data to be rendered to the template engine instance.
24
     * @param string $filePath
25
     * @param array $data
26
     * @return string
27
     * @throws \SmartyException
28
     */
29
    public function renderFromFileTemplate(string $filePath, array $data): string
30
    {
31
        $this->smarty->setData($data);
32
        return $this->smarty->fetch($filePath);
33
    }
34
35
    /**
36
     * Passes a template string and data to be rendered to the template engine
37
     * instance.
38
     * @param string $string
39
     * @param array $data
40
     * @return string
41
     * @throws \SmartyException
42
     */
43
    public function renderFromStringTemplate(string $string, array $data): string
44
    {
45
        $this->smarty->setData($data);
46
        return $this->smarty->fetch("string:$string");
47
    }
48
}
49