Passed
Push — master ( 7b7005...55ec05 )
by Brent
02:29
created

SmartyEngine::getTemplateExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Template\Smarty;
4
5
use \Smarty;
6
use Brendt\Stitcher\Template\TemplateEngine;
7
use Symfony\Component\Finder\SplFileInfo;
8
9
/**
10
 * The Smarty template engine.
11
 */
12
class SmartyEngine extends Smarty implements TemplateEngine
13
{
14
    public function __construct($templateDir = './src', $cacheDir = './.cache') {
15
        parent::__construct();
16
17
        $this->addTemplateDir($templateDir);
18
        $this->setCompileDir($cacheDir);
19
        $this->addPluginsDir([__DIR__]);
20
21
        $this->caching = false;
22
    }
23
24
    public function renderTemplate(SplFileInfo $template) {
25
        return $this->fetch($template->getRealPath());
26
    }
27
28
    public function addTemplateVariables(array $variables) {
29
        foreach ($variables as $name => $variable) {
30
            $this->assign($name, $variable);
31
        }
32
33
        return $this;
34
    }
35
36
    public function clearTemplateVariables() {
37
        $this->clearAllAssign();
38
39
        return $this;
40
    }
41
42
    public function addTemplateVariable($name, $value) {
43
        $this->assign($name, $value);
44
45
        return $this;
46
    }
47
48
    public function hasTemplateVariable(string $name) : bool {
49
        return $this->getTemplateVars($name) != null;
50
    }
51
52
    public function clearTemplateVariable($variable) {
53
        $this->clearAssign($variable);
54
55
        return $this;
56
    }
57
58
    public function getTemplateExtensions(): array {
59
        return ['tpl'];
60
    }
61
}
62