Test Failed
Push — main ( 397c3b...9ee4d3 )
by Rafael
43:59
created

ViewController::view()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 2
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* Copyright (C) 2024      Rafael San José      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Alxarafe\Base;
20
21
use Jenssegers\Blade\Blade;
22
23
/**
24
 * Class ViewController. The views controller adds support for views to the generic controller.
25
 *
26
 * @package Alxarafe\Base
27
 */
28
abstract class ViewController extends GenericController
29
{
30
    /**
31
     * Theme name. TODO: Has to be updated according to the configuration.
32
     *
33
     * @var string
34
     */
35
    public $theme = 'eldy';
36
37
    public function __destruct()
38
    {
39
        $vars = ['self' => $this];
40
        $viewPaths = [
41
            BASE_PATH . '/Templates',
42
            BASE_PATH . '/Templates/theme/' . $this->theme,
43
        ];
44
        $cachePaths = realpath(BASE_PATH . '/../tmp') . '/blade';
45
        if (!is_dir($cachePaths) && !mkdir($cachePaths) && !is_dir($cachePaths)) {
46
            die('Could not create cache directory for templates.');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
47
        }
48
        $blade = new Blade($viewPaths, $cachePaths);
49
        echo $blade->render($this->template, $vars);
50
    }
51
}
52