1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
session_start(); |
4
|
|
|
|
5
|
|
|
require __DIR__.'/../vendor/autoload.php'; |
6
|
|
|
require __DIR__.'/Routes/default.php'; |
7
|
|
|
|
8
|
|
|
use HnrAzevedo\Http\Factory; |
|
|
|
|
9
|
|
|
use HnrAzevedo\Http\Uri; |
|
|
|
|
10
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
|
|
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
|
|
|
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
|
|
|
13
|
|
|
|
14
|
|
|
use HnrAzevedo\Router\Router; |
|
|
|
|
15
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
|
|
|
16
|
|
|
|
17
|
|
|
try{ |
18
|
|
|
$serverRequest = (new Factory())->createServerRequest($_SERVER['REQUEST_METHOD'], new Uri($_SERVER['REQUEST_URI'])); |
19
|
|
|
|
20
|
|
|
class App implements MiddlewareInterface{ |
21
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
22
|
|
|
{ |
23
|
|
|
if(empty($request->getAttribute('route'))) |
24
|
|
|
{ |
25
|
|
|
throw new Exception('Page not found', 404); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$request->getAttribute('route')['action'](); |
29
|
|
|
|
30
|
|
|
return (new Factory())->createResponse(200); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
define('GLOBAL_MIDDLEWARES',[ |
35
|
|
|
Router::class, |
36
|
|
|
App::class |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
function nextExample(RequestHandlerInterface $defaultHandler): RequestHandlerInterface |
40
|
|
|
{ |
41
|
|
|
return new class (GLOBAL_MIDDLEWARES, $defaultHandler) implements RequestHandlerInterface { |
42
|
|
|
private RequestHandlerInterface $handler; |
43
|
|
|
private array $pipeline; |
44
|
|
|
|
45
|
|
|
public function __construct(array $pipeline, RequestHandlerInterface $handler) |
46
|
|
|
{ |
47
|
|
|
$this->handler = $handler; |
48
|
|
|
$this->pipeline = $pipeline; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface |
52
|
|
|
{ |
53
|
|
|
if (!$middleware = array_shift($this->pipeline)) { |
54
|
|
|
return $this->handler->handle($request); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$next = clone $this; |
58
|
|
|
$this->pipeline = []; |
59
|
|
|
|
60
|
|
|
$response = (new $middleware())->process($request, $next); |
61
|
|
|
|
62
|
|
|
return $response; |
63
|
|
|
} |
64
|
|
|
}; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
function runMiddlewares($serverRequest) |
69
|
|
|
{ |
70
|
|
|
nextExample(new class implements RequestHandlerInterface{ |
71
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface |
72
|
|
|
{ |
73
|
|
|
return (new Factory())->createResponse(200); |
74
|
|
|
} |
75
|
|
|
})->handle($serverRequest); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
runMiddlewares($serverRequest); |
79
|
|
|
|
80
|
|
|
}catch(Exception $er){ |
81
|
|
|
|
82
|
|
|
die("Code Error: {$er->getCode()}<br>Line: {$er->getLine()}<br>File: {$er->getFile()}<br>Message: {$er->getMessage()}."); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
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