Completed
Push — master ( 03f7a5...12ecd6 )
by Markus
02:37
created

HtmlOutput   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 43
ccs 0
cts 26
cp 0
rs 10
wmc 4
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A setVariable() 0 4 1
A setTemplate() 0 4 1
A output() 0 5 1
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('baseUrlRelative', $this->config->baseUrlRelative);
0 ignored issues
show
Bug introduced by
The property baseUrlRelative does not seem to exist. Did you mean baseUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
32
        $this->setVariable('themeUrl', $this->config->baseUrlRelative . $this->config->paths['themes'] . $this->config->site['theme'] . '/');
0 ignored issues
show
Bug introduced by
The property baseUrlRelative does not seem to exist. Did you mean baseUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
33
        $this->setVariable('requestUri', $_SERVER['REQUEST_URI']);
34
    }
35
36
    public function setVariable($name, $value)
37
    {
38
        $this->tplVars[$name] = $value;
39
    }
40
41
    public function setTemplate($tplName)
42
    {
43
        $this->template = $tplName;
44
    }
45
46
    public function output()
47
    {
48
        $tpl = $this->mustache->loadTemplate($this->template);
49
        echo $tpl->render($this->tplVars);
50
    }
51
}
52