1 | <?php |
||
27 | class Application extends Container |
||
28 | { |
||
29 | /** |
||
30 | * The FastD version. |
||
31 | * |
||
32 | * @const string |
||
33 | */ |
||
34 | const VERSION = '3.1.0 (release candidate)'; |
||
35 | |||
36 | /** |
||
37 | * @var Application |
||
38 | */ |
||
39 | public static $app; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $path; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $name; |
||
50 | |||
51 | /** |
||
52 | * @var bool |
||
53 | */ |
||
54 | protected $booted = false; |
||
55 | |||
56 | /** |
||
57 | * AppKernel constructor. |
||
58 | * |
||
59 | * @param $path |
||
60 | */ |
||
61 | 54 | public function __construct($path) |
|
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | 46 | public function getName() |
|
79 | |||
80 | /** |
||
81 | * @return bool |
||
82 | */ |
||
83 | 5 | public function isBooted() |
|
87 | |||
88 | /** |
||
89 | * @return string |
||
90 | */ |
||
91 | 56 | public function getPath() |
|
95 | |||
96 | 54 | public function bootstrap() |
|
109 | |||
110 | /** |
||
111 | * @param ServiceProviderInterface[] $services |
||
112 | */ |
||
113 | 54 | protected function registerServicesProviders(array $services) |
|
120 | |||
121 | /** |
||
122 | * @param ServerRequestInterface $request |
||
123 | * |
||
124 | * @return Response |
||
125 | */ |
||
126 | 16 | public function handleRequest(ServerRequestInterface $request) |
|
135 | |||
136 | /** |
||
137 | * @param Response $response |
||
138 | */ |
||
139 | 5 | public function handleResponse(Response $response) |
|
143 | |||
144 | /** |
||
145 | * @param ServerRequestInterface $request |
||
146 | * @param Exception $e |
||
147 | * |
||
148 | * @return Http\JsonResponse |
||
149 | */ |
||
150 | 10 | public function handleException(ServerRequestInterface $request, Exception $e) |
|
151 | { |
||
152 | 10 | $statusCode = ($e instanceof HttpException) ? $e->getStatusCode() : $e->getCode(); |
|
153 | |||
154 | 10 | if (!array_key_exists($statusCode, Response::$statusTexts)) { |
|
155 | 5 | $statusCode = 502; |
|
156 | 5 | } |
|
157 | |||
158 | 10 | $handle = config()->get('exception.handle'); |
|
159 | |||
160 | 10 | $response = json($handle($e), $statusCode); |
|
161 | |||
162 | try { |
||
163 | 10 | logger()->error($request->getMethod().' '.$request->getUri()->getPath(), [ |
|
164 | 8 | 'ip' => get_local_ip(), |
|
165 | 8 | 'status' => $response->getStatusCode(), |
|
166 | 8 | 'get' => $request->getQueryParams(), |
|
167 | 8 | 'post' => $request->getParsedBody(), |
|
168 | 8 | 'msg' => $e->getMessage(), |
|
169 | 8 | 'code' => $e->getCode(), |
|
170 | 8 | 'file' => $e->getFile(), |
|
171 | 8 | 'line' => $e->getLine(), |
|
172 | 8 | 'trace' => explode("\n", $e->getTraceAsString()), |
|
173 | 8 | ]); |
|
174 | |||
175 | 8 | return $response; |
|
176 | 2 | } catch (ServiceNotFoundException $e) { |
|
177 | 2 | return $response; |
|
178 | } |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @return int |
||
183 | */ |
||
184 | public function run() |
||
194 | |||
195 | /** |
||
196 | * @param ServerRequestInterface $request |
||
197 | * @param ResponseInterface $response |
||
198 | * |
||
199 | * @return int |
||
200 | */ |
||
201 | 5 | public function shutdown(ServerRequestInterface $request, ResponseInterface $response) |
|
216 | } |
||
217 |