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\Controller\Trait; |
20
|
|
|
|
21
|
|
|
use Jenssegers\Blade\Blade; |
|
|
|
|
22
|
|
|
|
23
|
|
|
trait ViewTrait |
24
|
|
|
{ |
25
|
|
|
public static $messages = []; |
26
|
|
|
/** |
27
|
|
|
* Theme name. TODO: Has to be updated according to the configuration. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
public $theme; |
32
|
|
|
/** |
33
|
|
|
* Code lang for <html lang> tag |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $lang = 'en'; |
38
|
|
|
public $body_class; |
39
|
|
|
public $templatesPath; |
40
|
|
|
public $template; |
41
|
|
|
public $title; |
42
|
|
|
public $alerts; |
43
|
|
|
|
44
|
|
|
public static function addMessage($message) |
45
|
|
|
{ |
46
|
|
|
self::$messages[]['success'] = $message; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public static function addAdvice($message) |
50
|
|
|
{ |
51
|
|
|
self::$messages[]['warning'] = $message; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function addError($message) |
55
|
|
|
{ |
56
|
|
|
self::$messages[]['danger'] = $message; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function __destruct() |
60
|
|
|
{ |
61
|
|
|
if (!isset($this->template)) { |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!isset($this->theme)) { |
66
|
|
|
$this->theme = 'alixar'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (!isset($this->title)) { |
70
|
|
|
$this->title = 'Alixar'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->alerts = static::getMessages(); |
74
|
|
|
|
75
|
|
|
$vars = ['me' => $this]; |
76
|
|
|
$viewPaths = [ |
77
|
|
|
BASE_PATH . '/Templates', |
|
|
|
|
78
|
|
|
BASE_PATH . '/Templates/theme/' . $this->theme, |
79
|
|
|
BASE_PATH . '/Templates/common', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
if (isset($this->templatesPath)) { |
83
|
|
|
array_unshift($viewPaths, $this->templatesPath); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$cachePaths = realpath(BASE_PATH . '/..') . '/tmp/blade'; |
87
|
|
|
if (!is_dir($cachePaths) && !mkdir($cachePaths, 0777, true) && !is_dir($cachePaths)) { |
88
|
|
|
die('Could not create cache directory for templates: ' . $cachePaths); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
$blade = new Blade($viewPaths, $cachePaths); |
91
|
|
|
echo $blade->render($this->template, $vars); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public static function getMessages() |
95
|
|
|
{ |
96
|
|
|
$alerts = []; |
97
|
|
|
foreach (self::$messages as $message) { |
98
|
|
|
foreach ($message as $type => $text) { |
99
|
|
|
$alerts[] = [ |
100
|
|
|
'type' => $type, |
101
|
|
|
'text' => $text |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
self::$messages = []; |
106
|
|
|
return $alerts; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getTemplatesPath(): string |
110
|
|
|
{ |
111
|
|
|
return $this->templatesPath; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setTemplatesPath(string $path) |
115
|
|
|
{ |
116
|
|
|
$this->templatesPath = $path; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths