Template::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * The class is responsible for rendering HTML templates
4
 *
5
 * PHP version 5.5
6
 *
7
 * @category   OpCacheGUI
8
 * @package    Presentation
9
 * @author     Pieter Hordijk <[email protected]>
10
 * @copyright  Copyright (c) 2014 Pieter Hordijk <https://github.com/PeeHaa>
11
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
12
 * @version    1.0.0
13
 */
14
namespace OpCacheGUI\Presentation;
15
16
use OpCacheGUI\I18n\Translator;
17
18
/**
19
 * The class is responsible for rendering HTML templates
20
 *
21
 * @category   OpCacheGUI
22
 * @package    Presentation
23
 * @author     Pieter Hordijk <[email protected]>
24
 */
25
abstract class Template implements Renderer
26
{
27
    /**
28
     * @var string The directory where all the templates are stored
29
     */
30
    protected $templateDirectory;
31
32
    /**
33
     * @var \OpCacheGUI\I18n\Translator Instance of a translation service
34
     */
35
    protected $translator;
36
37
    /**
38
     * @var array List of template variables
39
     */
40
    protected $variables = [];
41
42
    /**
43
     * Creates instance
44
     *
45
     * @param string                      $templateDirectory The directory where all the templates are stored
46
     * @param \OpCacheGUI\I18n\Translator $translator        Instance of a translation service
47
     */
48 8
    public function __construct($templateDirectory, Translator $translator)
49
    {
50 8
        $this->templateDirectory = $templateDirectory;
51 8
        $this->translator        = $translator;
52 8
    }
53
54
    /**
55
     * Magically get template variables, because magic that's why
56
     *
57
     * Disclaimer: I am fully aware this kinda sucks and will bite me in the arse
58
     *             at some point, so don't bother bugging me about this :-)
59
     *
60
     * @param mixed The key of which to get the data
61
     *
62
     * @return mixed The value which belongs to the key provided
63
     */
64 2
    public function __get($key)
65
    {
66 2
        if (!array_key_exists($key, $this->variables)) {
67 1
            return null;
68
        }
69
70 1
        return $this->variables[$key];
71
    }
72
73
    /**
74
     * Magically check whether magic variables exist in a magical way using magic
75
     *
76
     * @param mixed The key to check
77
     *
78
     * @return boolean true when tha magical thing is set
79
     */
80 2
    public function __isset($key)
81
    {
82 2
        return isset($this->variables[$key]);
83
    }
84
}
85