Passed
Branch master (b0d099)
by Markus
03:49
created

HtmlOutput::setTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SSpkS\Output;
4
5
use \Mustache_Engine;
6
use \Mustache_Loader_FilesystemLoader;
7
use \Mustache_Logger_StreamLogger;
8
9
class HtmlOutput
10
{
11
    private $config;
12
    private $mustache;
13
    private $tplVars;
14
    private $template;
15
16
    public function __construct(\SSpkS\Config $config)
17
    {
18
        $this->config = $config;
19
        $tplBase  = $this->config->basePath . DIRECTORY_SEPARATOR . $this->config->paths['themes'];
20
        $tplBase .= $this->config->site['theme'] . DIRECTORY_SEPARATOR . 'templates';
21
22
        $this->mustache = new Mustache_Engine(array(
23
            'loader'          => new Mustache_Loader_FilesystemLoader($tplBase),
24
            'partials_loader' => new Mustache_Loader_FilesystemLoader($tplBase . '/partials'),
25
            'charset'         => 'utf-8',
26
            'logger'          => new Mustache_Logger_StreamLogger('php://stderr'),
27
        ));
28
29
        $this->setVariable('siteName', $this->config->site['name']);
30
        $this->setVariable('baseUrl', $this->config->baseUrl);
31
        $this->setVariable('themeUrl', $this->config->baseUrl . $this->config->paths['themes'] . $this->config->site['theme'] . '/');
32
        $this->setVariable('requestUri', $_SERVER['REQUEST_URI']);
33
    }
34
35
    public function setVariable($name, $value)
36
    {
37
        $this->tplVars[$name] = $value;
38
    }
39
40
    public function setTemplate($tplName)
41
    {
42
        $this->template = $tplName;
43
    }
44
45
    public function output()
46
    {
47
        $tpl = $this->mustache->loadTemplate($this->template);
48
        echo $tpl->render($this->tplVars);
49
    }
50
}
51