1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Http\Kernel; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Nip\Application\ApplicationInterface; |
7
|
|
|
use Nip\Dispatcher\ActionDispatcherMiddleware; |
|
|
|
|
8
|
|
|
use Nip\Http\Kernel\Traits\HandleExceptionsTrait; |
|
|
|
|
9
|
|
|
use Nip\Http\Response\Response; |
10
|
|
|
use Nip\Http\ServerMiddleware\Dispatcher; |
11
|
|
|
use Nip\Http\ServerMiddleware\Traits\HasServerMiddleware; |
12
|
|
|
use Nip\Request; |
13
|
|
|
use Nip\Router\Middleware\RouteResolverMiddleware; |
14
|
|
|
use Nip\Router\Router; |
15
|
|
|
use Nip\Session\Middleware\StartSession; |
|
|
|
|
16
|
|
|
use Psr\Http\Message\RequestInterface; |
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
18
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
19
|
|
|
use Symfony\Component\ErrorHandler\Error\FatalError; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request as SymfonyRequest; |
21
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
22
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
23
|
|
|
use Throwable; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Kernel |
27
|
|
|
* @package Nip\Http\Kernel |
28
|
|
|
*/ |
29
|
|
|
class Kernel implements KernelInterface |
30
|
|
|
{ |
31
|
|
|
use Traits\HandleExceptions; |
32
|
|
|
use Traits\HasApplication; |
33
|
|
|
|
34
|
|
|
use HasServerMiddleware; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The router instance. |
38
|
|
|
* |
39
|
|
|
* @var Router |
40
|
|
|
*/ |
41
|
|
|
protected $router; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The application's route middleware groups. |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected $middlewareGroups = []; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The application's route middleware. |
52
|
|
|
* |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $routeMiddleware = []; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Create a new HTTP kernel instance. |
59
|
|
|
* |
60
|
|
|
* @param ApplicationInterface $app |
61
|
|
|
* @param Router $router |
62
|
|
|
*/ |
63
|
|
|
public function __construct(ApplicationInterface $app, Router $router) |
64
|
|
|
{ |
65
|
|
|
$this->app = $app; |
|
|
|
|
66
|
|
|
$this->router = $router; |
67
|
|
|
|
68
|
|
|
$this->pushMiddleware(StartSession::class); |
69
|
|
|
$this->pushMiddleware(RouteResolverMiddleware::class); |
70
|
|
|
$this->pushMiddleware(ActionDispatcherMiddleware::class); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Handle an incoming HTTP request. |
75
|
|
|
* |
76
|
|
|
* @param SymfonyRequest $request |
77
|
|
|
* @param int $type |
78
|
|
|
* @param bool $catch |
79
|
|
|
* @return ResponseInterface |
80
|
|
|
*/ |
81
|
|
|
public function handle( |
82
|
|
|
SymfonyRequest $request, |
83
|
|
|
int $type = HttpKernelInterface::MAIN_REQUEST, |
84
|
|
|
bool $catch = true |
85
|
|
|
): \Symfony\Component\HttpFoundation\Response { |
86
|
|
|
try { |
87
|
|
|
$this->getApplication()->share('request', $request); |
88
|
|
|
return $this->handleRaw($request, $type); |
|
|
|
|
89
|
|
|
} catch (Exception $e) { |
90
|
|
|
$this->reportException($e); |
91
|
|
|
$response = $this->renderException($request, $e); |
92
|
|
|
} catch (Throwable $e) { |
93
|
|
|
$this->reportException($e); |
94
|
|
|
$response = $this->renderException($request, $e); |
95
|
|
|
} |
96
|
|
|
// event(new Events\RequestHandled($request, $response)); |
97
|
|
|
return $response; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Handles a request to convert it to a response. |
102
|
|
|
* |
103
|
|
|
* @param ServerRequestInterface $request A Request instance |
104
|
|
|
* @param int $type The type of the request |
105
|
|
|
* |
106
|
|
|
* @return ResponseInterface A Response instance |
107
|
|
|
* |
108
|
|
|
* @throws \LogicException If one of the listener does not behave as expected |
109
|
|
|
* @throws NotFoundHttpException When controller cannot be found |
110
|
|
|
*/ |
111
|
|
|
protected function handleRaw(ServerRequestInterface $request, $type = self::MASTER_REQUEST) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
return ( |
114
|
|
|
new Dispatcher($this->middleware, $this->getApplication()->getContainer()) |
115
|
|
|
)->dispatch($request); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param Request $request |
120
|
|
|
* @param Response $response |
121
|
|
|
*/ |
122
|
|
|
public function terminate(RequestInterface $request, ResponseInterface $response) |
123
|
|
|
{ |
124
|
|
|
$this->terminateMiddleware($request, $response); |
125
|
|
|
$this->getApplication()->terminate(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function postRouting() |
129
|
|
|
{ |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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