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