1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lepton\Controller; |
4
|
|
|
|
5
|
|
|
use Lepton\Authenticator\UserAuthenticator; |
6
|
|
|
use Lepton\Core\Application; |
7
|
|
|
use Liquid\{Liquid, Template}; |
8
|
|
|
use Lepton\Boson\QuerySet; |
|
|
|
|
9
|
|
|
use Lepton\Http\Response\{SuccessResponse, RedirectResponse}; |
10
|
|
|
|
11
|
|
|
abstract class BaseController |
12
|
|
|
{ |
13
|
|
|
protected array $default_parameters; |
14
|
|
|
protected array $custom_filters; |
15
|
|
|
public string $baseLink; |
16
|
|
|
|
17
|
|
|
public function url($string){ |
18
|
|
|
return Application::getDir()."/".$string; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function render(string $view, array $parameters = array(), $headers = array()) |
22
|
|
|
{ |
23
|
|
|
Liquid::set('INCLUDE_SUFFIX', 'html'); |
24
|
|
|
Liquid::set('INCLUDE_PREFIX', ''); |
25
|
|
|
$path = "app/Views"; |
26
|
|
|
$template = new Template($path); |
27
|
|
|
$template->registerFilter(new SiteFilter()); |
|
|
|
|
28
|
|
|
|
29
|
|
|
if(isset($this->custom_filters)){ |
30
|
|
|
foreach($this->custom_filters as $filter){ |
31
|
|
|
$template->registerFilter(new $filter()); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
$template->parseFile($view); |
35
|
|
|
$parameters = array_map(function ($x) { |
36
|
|
|
if ($x instanceof QuerySet) { |
37
|
|
|
return $x->do(); |
38
|
|
|
} else { |
39
|
|
|
return $x; |
40
|
|
|
} |
41
|
|
|
}, $parameters); |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
$authenticator = new UserAuthenticator(); |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
$parameters["page"] = $_SERVER["REQUEST_URI"]; |
48
|
|
|
$parameters["logged_user"] = $authenticator->getLoggedUser(); |
49
|
|
|
$parameters["base_link"] = $this->baseLink; |
50
|
|
|
|
51
|
|
|
if (isset($this->default_parameters)) { |
52
|
|
|
$parameters = array_merge($parameters, $this->default_parameters); |
53
|
|
|
} |
54
|
|
|
return new SuccessResponse($template->render($parameters), headers: $headers); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function redirect($url, $htmx = false, $parse = true) |
59
|
|
|
{ |
60
|
|
|
return new RedirectResponse($url, $htmx, $parse); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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