1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.5.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Hooks; |
16
|
|
|
|
17
|
|
|
use Quantum\Libraries\Database\Database; |
|
|
|
|
18
|
|
|
use Quantum\Exceptions\RouteException; |
19
|
|
|
use Quantum\Routes\RouteController; |
20
|
|
|
use Twig\Loader\FilesystemLoader; |
21
|
|
|
use Quantum\Debugger\Debugger; |
22
|
|
|
use Quantum\Http\Response; |
23
|
|
|
use Twig\TwigFunction; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class HookDefaults |
27
|
|
|
* @package Quantum\Hooks |
28
|
|
|
*/ |
29
|
|
|
class HookDefaults implements HookInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Handle Headers |
34
|
|
|
* Allows Cross domain requests |
35
|
|
|
*/ |
36
|
|
|
public static function handleHeaders() |
37
|
|
|
{ |
38
|
|
|
Response::setHeader('Access-Control-Allow-Origin', '*'); |
39
|
|
|
Response::setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); |
40
|
|
|
Response::setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Page not found |
45
|
|
|
* @throws \Quantum\Exceptions\RouteException |
46
|
|
|
*/ |
47
|
|
|
public static function pageNotFound() |
48
|
|
|
{ |
49
|
|
|
throw RouteException::notFound(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Template renderer |
54
|
|
|
* @param array $data |
55
|
|
|
* @return string |
56
|
|
|
* @throws \Twig\Error\LoaderError |
57
|
|
|
* @throws \Twig\Error\RuntimeError |
58
|
|
|
* @throws \Twig\Error\SyntaxError |
59
|
|
|
*/ |
60
|
|
|
public static function templateRenderer(array $data): string |
61
|
|
|
{ |
62
|
|
|
$loader = new FilesystemLoader(modules_dir() . DS . current_module() . DS . 'Views'); |
63
|
|
|
$twig = new \Twig\Environment($loader, $data['configs']); |
64
|
|
|
|
65
|
|
|
$definedFunctions = get_defined_functions(); |
66
|
|
|
|
67
|
|
|
$allDefinedFuncitons = array_merge($definedFunctions['internal'], $definedFunctions['user']); |
68
|
|
|
|
69
|
|
|
foreach ($allDefinedFuncitons as $function) { |
70
|
|
|
if (function_exists($function)) { |
71
|
|
|
$twig->addFunction(new TwigFunction($function, $function)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $twig->render($data['view'] . '.php', $data['params']); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Updates debugger store |
80
|
|
|
* @param array $data |
81
|
|
|
*/ |
82
|
|
|
public static function updateDebuggerStore(array $data) |
83
|
|
|
{ |
84
|
|
|
$currentRoute = RouteController::getCurrentRoute(); |
85
|
|
|
|
86
|
|
|
$routeInfo = []; |
87
|
|
|
|
88
|
|
|
array_walk($currentRoute, function ($value, $key) use (&$routeInfo) { |
89
|
|
|
$routeInfo[ucfirst($key)] = $value; |
90
|
|
|
}); |
91
|
|
|
|
92
|
|
|
$routeInfo['View'] = current_module() . DS . 'Views' . DS . $data['view']; |
93
|
|
|
|
94
|
|
|
Debugger::addToStore(Debugger::ROUTES, 'info', $routeInfo); |
95
|
|
|
Debugger::addToStore(Debugger::QUERIES, 'info', Database::queryLog()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
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