Completed
Push — rework ( 42375a...b64e66 )
by Markus
02:35
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
20
        $this->mustache = new Mustache_Engine(array(
21
            'loader'          => new Mustache_Loader_FilesystemLoader($this->config->basePath . '/data/templates'),
22
            'partials_loader' => new Mustache_Loader_FilesystemLoader($this->config->basePath . '/data/templates/partials'),
23
            'charset'         => 'utf-8',
24
            'logger'          => new Mustache_Logger_StreamLogger('php://stderr'),
25
        ));
26
27
        $this->setVariable('siteName', $this->config->site['name']);
28
        $this->setVariable('baseUrl', $this->config->baseUrl);
29
        $this->setVariable('requestUri', $_SERVER['REQUEST_URI']);
30
    }
31
32
    public function setVariable($name, $value)
33
    {
34
        $this->tplVars[$name] = $value;
35
    }
36
37
    public function setTemplate($tplName)
38
    {
39
        $this->template = $tplName;
40
    }
41
42
    public function output()
43
    {
44
        $tpl = $this->mustache->loadTemplate($this->template);
45
        echo $tpl->render($this->tplVars);
46
    }
47
}
48