Test Failed
Push — main ( 8a0749...ac1aa2 )
by Rafael
44:34
created

DolibarrViewController::__destruct()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 15
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 23
rs 9.2222
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 DoliCore\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 DolibarrViewController extends DolibarrGenericController
29
{
30
    /**
31
     * Theme name. TODO: Has to be updated according to the configuration.
32
     *
33
     * @var string
34
     */
35
    public $theme;
36
37
    public function __destruct()
38
    {
39
        $this->theme = $_GET['theme'];
40
        if (empty($this->theme)) {
41
            $this->theme = 'adminlte';
42
        }
43
44
        if (!isset($this->template)) {
45
            $this->template = 'index';
46
        }
47
48
        $vars = ['me' => $this];
49
        $viewPaths = [
50
            BASE_PATH . '/Templates',
51
            BASE_PATH . '/Templates/theme/' . $this->theme,
52
            BASE_PATH . '/Templates/common',
53
        ];
54
        $cachePaths = realpath(BASE_PATH . '/../tmp') . '/blade';
55
        if (!is_dir($cachePaths) && !mkdir($cachePaths) && !is_dir($cachePaths)) {
56
            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...
57
        }
58
        $blade = new Blade($viewPaths, $cachePaths);
59
        echo $blade->render($this->template, $vars);
60
    }
61
}
62