1 | <?php |
||
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) |
|
84 | } |
||
85 |