Test Failed
Push — master ( a58c94...1bcec0 )
by Brent
03:26
created

SmartyEngine::addTemplateVariable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Template\Smarty;
4
5
use \Smarty;
6
use Brendt\Stitcher\Config;
7
use Brendt\Stitcher\Template\TemplateEngine;
8
use Symfony\Component\Finder\SplFileInfo;
9
10
/**
11
 * The Smarty template engine.
12
 */
13
class SmartyEngine extends Smarty implements TemplateEngine {
14
15
    /**
16
     * Create the Smarty engine, set the template- and cache directory; and add the plugin directory.
17
     */
18
    public function __construct() {
19
        parent::__construct();
20
21
        $templateFolder = Config::get('directories.template');
22
        $this->addTemplateDir($templateFolder);
23
24
        $this->setCompileDir(Config::get('directories.cache'));
25
        $this->addPluginsDir([__DIR__]);
26
27
        $this->caching = false;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function renderTemplate(SplFileInfo $template) {
34
        return $this->fetch($template->getRealPath());
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function addTemplateVariables(array $variables) {
41
        foreach ($variables as $name => $variable) {
42
            $this->assign($name, $variable);
43
        }
44
45
        return $this;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function clearTemplateVariables() {
52
        $this->clearAllAssign();
53
54
        return $this;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function addTemplateVariable($name, $value) {
61
        $this->assign($name, $value);
62
63
        return $this;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function clearTemplateVariable($variable) {
70
        $this->clearAssign($variable);
71
72
        return $this;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getTemplateExtension() {
79
        return 'tpl';
80
    }
81
}
82