Total Complexity | 10 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
7 | class Template |
||
8 | { |
||
9 | private $template; |
||
10 | private $templateSettings; |
||
11 | |||
12 | public function __construct($template = null) |
||
13 | { |
||
14 | $this->template = $this->getCurrentTemplate($template); |
||
15 | $this->templateSettings = $this->getCurrentSettings($this->template); |
||
16 | } |
||
17 | |||
18 | public static function forTemplate(string $template) |
||
19 | { |
||
20 | return new static($template); |
||
21 | } |
||
22 | |||
23 | private function getCurrentSettings(TemplateModel $template_model) |
||
24 | { |
||
25 | return $template_model->json; |
||
26 | } |
||
27 | |||
28 | private function getCurrentTemplate($template_slug) |
||
29 | { |
||
30 | if (is_null($template_slug)) { |
||
31 | $template = TemplateModel::where('active', true)->where('type', 'default')->first(); |
||
32 | } else { |
||
33 | $template = TemplateModel::where('slug', $template_slug)->first(); |
||
34 | } |
||
35 | |||
36 | if (is_null($template)) { |
||
37 | throw new Exception('Whoops! No Template Defined...'); |
||
|
|||
38 | } |
||
39 | |||
40 | return $template; |
||
41 | } |
||
42 | |||
43 | public function getSetting($var) |
||
44 | { |
||
45 | $setting = $this->resolveSetting($var, $this->templateSettings); |
||
46 | |||
47 | return !is_null($setting) ? $setting : null; |
||
48 | } |
||
49 | |||
50 | private function resolveSetting($var, $settings) |
||
59 | } |
||
60 | } |
||
61 |