@@ -181,7 +181,7 @@ |
||
181 | 181 | */ |
182 | 182 | protected function dispatchToRouter() |
183 | 183 | { |
184 | - return function ($request) { |
|
184 | + return function($request) { |
|
185 | 185 | $this->app->instance('request', $request); |
186 | 186 | |
187 | 187 | return $this->router->dispatch($request); |
@@ -36,295 +36,295 @@ |
||
36 | 36 | */ |
37 | 37 | class Lenevor implements LenevorContract |
38 | 38 | { |
39 | - /** |
|
40 | - * The application implementation. |
|
41 | - * |
|
42 | - * @var \Syscodes\Components\Contracts\Core\Application $app |
|
43 | - */ |
|
44 | - protected $app; |
|
39 | + /** |
|
40 | + * The application implementation. |
|
41 | + * |
|
42 | + * @var \Syscodes\Components\Contracts\Core\Application $app |
|
43 | + */ |
|
44 | + protected $app; |
|
45 | 45 | |
46 | - /** |
|
47 | - * The bootstrap classes for the application. |
|
48 | - * |
|
49 | - * @var array $bootstrappers |
|
50 | - */ |
|
51 | - protected $bootstrappers = [ |
|
52 | - \Syscodes\Components\Core\Bootstrap\BootDetectEnvironment::class, |
|
53 | - \Syscodes\Components\Core\Bootstrap\BootConfiguration::class, |
|
54 | - \Syscodes\Components\Core\Bootstrap\BootHandleExceptions::class, |
|
55 | - \Syscodes\Components\Core\Bootstrap\BootRegisterFacades::class, |
|
56 | - \Syscodes\Components\Core\Bootstrap\BootRegisterProviders::class, |
|
57 | - \Syscodes\Components\Core\Bootstrap\BootProviders::class, |
|
58 | - ]; |
|
46 | + /** |
|
47 | + * The bootstrap classes for the application. |
|
48 | + * |
|
49 | + * @var array $bootstrappers |
|
50 | + */ |
|
51 | + protected $bootstrappers = [ |
|
52 | + \Syscodes\Components\Core\Bootstrap\BootDetectEnvironment::class, |
|
53 | + \Syscodes\Components\Core\Bootstrap\BootConfiguration::class, |
|
54 | + \Syscodes\Components\Core\Bootstrap\BootHandleExceptions::class, |
|
55 | + \Syscodes\Components\Core\Bootstrap\BootRegisterFacades::class, |
|
56 | + \Syscodes\Components\Core\Bootstrap\BootRegisterProviders::class, |
|
57 | + \Syscodes\Components\Core\Bootstrap\BootProviders::class, |
|
58 | + ]; |
|
59 | 59 | |
60 | - /** |
|
61 | - * Get the application's middleware. |
|
62 | - * |
|
63 | - * @var array $middleware |
|
64 | - */ |
|
65 | - protected $middleware = []; |
|
60 | + /** |
|
61 | + * Get the application's middleware. |
|
62 | + * |
|
63 | + * @var array $middleware |
|
64 | + */ |
|
65 | + protected $middleware = []; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Get the application's middleware groups. |
|
69 | - * |
|
70 | - * @var array $middlewareGroups |
|
71 | - */ |
|
72 | - protected $middlewareGroups = []; |
|
67 | + /** |
|
68 | + * Get the application's middleware groups. |
|
69 | + * |
|
70 | + * @var array $middlewareGroups |
|
71 | + */ |
|
72 | + protected $middlewareGroups = []; |
|
73 | 73 | |
74 | - /** |
|
75 | - * The priority list of middleware. |
|
76 | - * |
|
77 | - * @var string[] $middlwarePriority |
|
78 | - */ |
|
79 | - protected $middlwarePriority = [ |
|
80 | - \Syscodes\Components\Cookie\Middleware\EncryptCookies::class, |
|
81 | - \Syscodes\Components\Session\Middleware\StartSession::class, |
|
82 | - \Syscodes\Components\Auth\Middleware\Authenticate::class, |
|
83 | - ]; |
|
74 | + /** |
|
75 | + * The priority list of middleware. |
|
76 | + * |
|
77 | + * @var string[] $middlwarePriority |
|
78 | + */ |
|
79 | + protected $middlwarePriority = [ |
|
80 | + \Syscodes\Components\Cookie\Middleware\EncryptCookies::class, |
|
81 | + \Syscodes\Components\Session\Middleware\StartSession::class, |
|
82 | + \Syscodes\Components\Auth\Middleware\Authenticate::class, |
|
83 | + ]; |
|
84 | 84 | |
85 | - /** |
|
86 | - * The router instance. |
|
87 | - * |
|
88 | - * @var \Syscodes\Components\Routing\Router $router |
|
89 | - */ |
|
90 | - protected $router; |
|
85 | + /** |
|
86 | + * The router instance. |
|
87 | + * |
|
88 | + * @var \Syscodes\Components\Routing\Router $router |
|
89 | + */ |
|
90 | + protected $router; |
|
91 | 91 | |
92 | - /** |
|
93 | - * Get the application's route middleware. |
|
94 | - * |
|
95 | - * @var array $routeMiddleware |
|
96 | - */ |
|
97 | - protected $routeMiddleware = []; |
|
92 | + /** |
|
93 | + * Get the application's route middleware. |
|
94 | + * |
|
95 | + * @var array $routeMiddleware |
|
96 | + */ |
|
97 | + protected $routeMiddleware = []; |
|
98 | 98 | |
99 | - /** |
|
100 | - * Total app execution time. |
|
101 | - * |
|
102 | - * @var float $totalTime |
|
103 | - */ |
|
104 | - protected $totalTime; |
|
99 | + /** |
|
100 | + * Total app execution time. |
|
101 | + * |
|
102 | + * @var float $totalTime |
|
103 | + */ |
|
104 | + protected $totalTime; |
|
105 | 105 | |
106 | - /** |
|
107 | - * Constructor. Lenevor class instance. |
|
108 | - * |
|
109 | - * @param \Syscodes\Components\Contracts\Core\Application $app |
|
110 | - * @param \Syscodes\Components\Routing\Router $router |
|
111 | - * |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public function __construct(Application $app, Router $router) |
|
115 | - { |
|
116 | - $this->app = $app; |
|
117 | - $this->router = $router; |
|
106 | + /** |
|
107 | + * Constructor. Lenevor class instance. |
|
108 | + * |
|
109 | + * @param \Syscodes\Components\Contracts\Core\Application $app |
|
110 | + * @param \Syscodes\Components\Routing\Router $router |
|
111 | + * |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public function __construct(Application $app, Router $router) |
|
115 | + { |
|
116 | + $this->app = $app; |
|
117 | + $this->router = $router; |
|
118 | 118 | |
119 | - $this->syncMiddlewareRoute(); |
|
120 | - } |
|
119 | + $this->syncMiddlewareRoute(); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Initializes the framework, this can only be called once. |
|
124 | - * Launch the application. |
|
125 | - * |
|
126 | - * @param \Syscodes\Components\http\Request $request |
|
127 | - * |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - public function handle($request) |
|
131 | - { |
|
132 | - try { |
|
133 | - $response = $this->sendRequestThroughRouter($request); |
|
134 | - } catch (Throwable $e) { |
|
135 | - $this->reportException($e); |
|
122 | + /** |
|
123 | + * Initializes the framework, this can only be called once. |
|
124 | + * Launch the application. |
|
125 | + * |
|
126 | + * @param \Syscodes\Components\http\Request $request |
|
127 | + * |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public function handle($request) |
|
131 | + { |
|
132 | + try { |
|
133 | + $response = $this->sendRequestThroughRouter($request); |
|
134 | + } catch (Throwable $e) { |
|
135 | + $this->reportException($e); |
|
136 | 136 | |
137 | - $response = $this->renderException($request, $e); |
|
138 | - } |
|
137 | + $response = $this->renderException($request, $e); |
|
138 | + } |
|
139 | 139 | |
140 | - return $response; |
|
141 | - } |
|
140 | + return $response; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Send the given request through the router. |
|
145 | - * |
|
146 | - * @param \Syscodes\Components\Http\Request $request |
|
147 | - * |
|
148 | - * @return \Syscodes\Components\Http\Response |
|
149 | - */ |
|
150 | - protected function sendRequestThroughRouter($request) |
|
151 | - { |
|
152 | - $this->app->instance('request', $request); |
|
143 | + /** |
|
144 | + * Send the given request through the router. |
|
145 | + * |
|
146 | + * @param \Syscodes\Components\Http\Request $request |
|
147 | + * |
|
148 | + * @return \Syscodes\Components\Http\Response |
|
149 | + */ |
|
150 | + protected function sendRequestThroughRouter($request) |
|
151 | + { |
|
152 | + $this->app->instance('request', $request); |
|
153 | 153 | |
154 | - Facade::clearResolvedInstance('request'); |
|
154 | + Facade::clearResolvedInstance('request'); |
|
155 | 155 | |
156 | - // Load configuration system |
|
157 | - $this->bootstrap(); |
|
156 | + // Load configuration system |
|
157 | + $this->bootstrap(); |
|
158 | 158 | |
159 | - return (new Pipeline($this->app)) |
|
160 | - ->send($request) |
|
161 | - ->through($this->app->skipGoingMiddleware() ? [] : $this->middleware) |
|
162 | - ->then($this->dispatchToRouter()); |
|
163 | - } |
|
159 | + return (new Pipeline($this->app)) |
|
160 | + ->send($request) |
|
161 | + ->through($this->app->skipGoingMiddleware() ? [] : $this->middleware) |
|
162 | + ->then($this->dispatchToRouter()); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Bootstrap the application for HTTP requests. |
|
167 | - * |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - protected function bootstrap(): void |
|
171 | - { |
|
172 | - if ( ! $this->app->hasBeenBootstrapped()) { |
|
173 | - $this->app->bootstrapWith($this->bootstrappers()); |
|
174 | - } |
|
175 | - } |
|
165 | + /** |
|
166 | + * Bootstrap the application for HTTP requests. |
|
167 | + * |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + protected function bootstrap(): void |
|
171 | + { |
|
172 | + if ( ! $this->app->hasBeenBootstrapped()) { |
|
173 | + $this->app->bootstrapWith($this->bootstrappers()); |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Get the bootstrap classes for the application. |
|
179 | - * |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function bootstrappers(): array |
|
183 | - { |
|
184 | - return $this->bootstrappers; |
|
185 | - } |
|
177 | + /** |
|
178 | + * Get the bootstrap classes for the application. |
|
179 | + * |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function bootstrappers(): array |
|
183 | + { |
|
184 | + return $this->bootstrappers; |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Sync the current state of the middleware to the router. |
|
189 | - * |
|
190 | - * @return void |
|
191 | - */ |
|
192 | - protected function syncMiddlewareRoute(): void |
|
193 | - { |
|
194 | - $this->router->middlewarePriority = $this->middlwarePriority; |
|
187 | + /** |
|
188 | + * Sync the current state of the middleware to the router. |
|
189 | + * |
|
190 | + * @return void |
|
191 | + */ |
|
192 | + protected function syncMiddlewareRoute(): void |
|
193 | + { |
|
194 | + $this->router->middlewarePriority = $this->middlwarePriority; |
|
195 | 195 | |
196 | - foreach ($this->middlewareGroups as $key => $middleware) { |
|
197 | - $this->router->middlewareGroup($key, $middleware); |
|
198 | - } |
|
196 | + foreach ($this->middlewareGroups as $key => $middleware) { |
|
197 | + $this->router->middlewareGroup($key, $middleware); |
|
198 | + } |
|
199 | 199 | |
200 | - foreach ($this->routeMiddleware as $key => $middleware) { |
|
201 | - $this->router->aliasMiddleware($key, $middleware); |
|
202 | - } |
|
203 | - } |
|
200 | + foreach ($this->routeMiddleware as $key => $middleware) { |
|
201 | + $this->router->aliasMiddleware($key, $middleware); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Get the dispatcher of routes. |
|
207 | - * |
|
208 | - * @return \Closure |
|
209 | - */ |
|
210 | - protected function dispatchToRouter() |
|
211 | - { |
|
212 | - return function ($request) { |
|
213 | - $this->app->instance('request', $request); |
|
205 | + /** |
|
206 | + * Get the dispatcher of routes. |
|
207 | + * |
|
208 | + * @return \Closure |
|
209 | + */ |
|
210 | + protected function dispatchToRouter() |
|
211 | + { |
|
212 | + return function ($request) { |
|
213 | + $this->app->instance('request', $request); |
|
214 | 214 | |
215 | - return $this->router->dispatch($request); |
|
216 | - }; |
|
217 | - } |
|
215 | + return $this->router->dispatch($request); |
|
216 | + }; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Call the finalize method on any terminable middleware. |
|
221 | - * |
|
222 | - * @param \Syscodes\Components\Http\Request $request |
|
223 | - * @param \Syscodes\Components\Http\Response $response |
|
224 | - * |
|
225 | - * @return void |
|
226 | - */ |
|
227 | - public function finalize($request, $response): void |
|
228 | - { |
|
229 | - $this->finalizeMiddleware($request, $response); |
|
230 | - } |
|
219 | + /** |
|
220 | + * Call the finalize method on any terminable middleware. |
|
221 | + * |
|
222 | + * @param \Syscodes\Components\Http\Request $request |
|
223 | + * @param \Syscodes\Components\Http\Response $response |
|
224 | + * |
|
225 | + * @return void |
|
226 | + */ |
|
227 | + public function finalize($request, $response): void |
|
228 | + { |
|
229 | + $this->finalizeMiddleware($request, $response); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Call the finalize method on any terminable middleware. |
|
234 | - * |
|
235 | - * @param \Syscodes\Components\Http\Request $request |
|
236 | - * @param \Syscodes\Components\Http\Response $response |
|
237 | - * |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - protected function finalizeMiddleware($request, $response): void |
|
241 | - { |
|
242 | - $middlewares = $this->app->skipGoingMiddleware() ? [] : array_merge( |
|
243 | - $this->gatherRouteMiddleware($request), |
|
244 | - $this->middleware |
|
245 | - ); |
|
232 | + /** |
|
233 | + * Call the finalize method on any terminable middleware. |
|
234 | + * |
|
235 | + * @param \Syscodes\Components\Http\Request $request |
|
236 | + * @param \Syscodes\Components\Http\Response $response |
|
237 | + * |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + protected function finalizeMiddleware($request, $response): void |
|
241 | + { |
|
242 | + $middlewares = $this->app->skipGoingMiddleware() ? [] : array_merge( |
|
243 | + $this->gatherRouteMiddleware($request), |
|
244 | + $this->middleware |
|
245 | + ); |
|
246 | 246 | |
247 | - foreach ($middlewares as $middleware) { |
|
248 | - if ( ! is_string($middleware)) { |
|
249 | - continue; |
|
250 | - } |
|
247 | + foreach ($middlewares as $middleware) { |
|
248 | + if ( ! is_string($middleware)) { |
|
249 | + continue; |
|
250 | + } |
|
251 | 251 | |
252 | - [$name] = $this->parseMiddleware($middleware); |
|
252 | + [$name] = $this->parseMiddleware($middleware); |
|
253 | 253 | |
254 | - $instance = $this->app->make($name); |
|
254 | + $instance = $this->app->make($name); |
|
255 | 255 | |
256 | - if (method_exists($instance, 'finalize')) { |
|
257 | - $instance->finalize($request, $response); |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
256 | + if (method_exists($instance, 'finalize')) { |
|
257 | + $instance->finalize($request, $response); |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * Gather the route middleware for the given request. |
|
264 | - * |
|
265 | - * @param \Syscodes\Components\Http\Request $request |
|
266 | - * |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - protected function gatherRouteMiddleware($request): array |
|
270 | - { |
|
271 | - if ($route = $request->route()) { |
|
272 | - return $this->router->gatherRouteMiddleware($route); |
|
273 | - } |
|
262 | + /** |
|
263 | + * Gather the route middleware for the given request. |
|
264 | + * |
|
265 | + * @param \Syscodes\Components\Http\Request $request |
|
266 | + * |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + protected function gatherRouteMiddleware($request): array |
|
270 | + { |
|
271 | + if ($route = $request->route()) { |
|
272 | + return $this->router->gatherRouteMiddleware($route); |
|
273 | + } |
|
274 | 274 | |
275 | - return []; |
|
276 | - } |
|
275 | + return []; |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Parse a middleware string to get the name and parameters. |
|
280 | - * |
|
281 | - * @param string $middleware |
|
282 | - * |
|
283 | - * @return array |
|
284 | - */ |
|
285 | - protected function parseMiddleware($middleware): array |
|
286 | - { |
|
287 | - [$name, $parameters] = array_pad(explode(':', $middleware, 2), 2, []); |
|
278 | + /** |
|
279 | + * Parse a middleware string to get the name and parameters. |
|
280 | + * |
|
281 | + * @param string $middleware |
|
282 | + * |
|
283 | + * @return array |
|
284 | + */ |
|
285 | + protected function parseMiddleware($middleware): array |
|
286 | + { |
|
287 | + [$name, $parameters] = array_pad(explode(':', $middleware, 2), 2, []); |
|
288 | 288 | |
289 | - if (is_string($parameters)) { |
|
290 | - $parameters = explode(',', $parameters); |
|
291 | - } |
|
289 | + if (is_string($parameters)) { |
|
290 | + $parameters = explode(',', $parameters); |
|
291 | + } |
|
292 | 292 | |
293 | - return [$name, $parameters]; |
|
293 | + return [$name, $parameters]; |
|
294 | 294 | } |
295 | 295 | |
296 | - /** |
|
297 | - * Gets the Lenevor application instance. |
|
298 | - * |
|
299 | - * @return void |
|
300 | - */ |
|
301 | - public function getApplication() |
|
302 | - { |
|
303 | - return $this->app; |
|
304 | - } |
|
296 | + /** |
|
297 | + * Gets the Lenevor application instance. |
|
298 | + * |
|
299 | + * @return void |
|
300 | + */ |
|
301 | + public function getApplication() |
|
302 | + { |
|
303 | + return $this->app; |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
307 | - * Report the exception to the exception handler. |
|
308 | - * |
|
309 | - * @param \Throwable $e |
|
310 | - * |
|
311 | - * @return void |
|
312 | - */ |
|
313 | - protected function reportException(Throwable $e) |
|
314 | - { |
|
315 | - return $this->app[ExceptionHandler::class]->report($e); |
|
316 | - } |
|
306 | + /** |
|
307 | + * Report the exception to the exception handler. |
|
308 | + * |
|
309 | + * @param \Throwable $e |
|
310 | + * |
|
311 | + * @return void |
|
312 | + */ |
|
313 | + protected function reportException(Throwable $e) |
|
314 | + { |
|
315 | + return $this->app[ExceptionHandler::class]->report($e); |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * Render the exception to a response. |
|
320 | - * |
|
321 | - * @param \Syscodes\Components\Http\Request $request |
|
322 | - * @param \Throwable $e |
|
323 | - * |
|
324 | - * @return \Syscodes\Components\Http\Response |
|
325 | - */ |
|
326 | - protected function renderException($request, Throwable $e) |
|
327 | - { |
|
328 | - return $this->app[ExceptionHandler::class]->render($request, $e); |
|
329 | - } |
|
318 | + /** |
|
319 | + * Render the exception to a response. |
|
320 | + * |
|
321 | + * @param \Syscodes\Components\Http\Request $request |
|
322 | + * @param \Throwable $e |
|
323 | + * |
|
324 | + * @return \Syscodes\Components\Http\Response |
|
325 | + */ |
|
326 | + protected function renderException($request, Throwable $e) |
|
327 | + { |
|
328 | + return $this->app[ExceptionHandler::class]->render($request, $e); |
|
329 | + } |
|
330 | 330 | } |
331 | 331 | \ No newline at end of file |
@@ -32,73 +32,73 @@ |
||
32 | 32 | */ |
33 | 33 | class HttpException extends LenevorException |
34 | 34 | { |
35 | - /** |
|
36 | - * Loader the Status Code HTTP. |
|
37 | - * |
|
38 | - * @var int $code |
|
39 | - */ |
|
40 | - protected $code; |
|
35 | + /** |
|
36 | + * Loader the Status Code HTTP. |
|
37 | + * |
|
38 | + * @var int $code |
|
39 | + */ |
|
40 | + protected $code; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Loader the headers HTTP. |
|
44 | - * |
|
45 | - * @var array $headers |
|
46 | - */ |
|
47 | - protected $headers; |
|
42 | + /** |
|
43 | + * Loader the headers HTTP. |
|
44 | + * |
|
45 | + * @var array $headers |
|
46 | + */ |
|
47 | + protected $headers; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Initialize constructor. |
|
51 | - * |
|
52 | - * @param int $statusCode |
|
53 | - * @param string $message |
|
54 | - * @param \Throwable $previous |
|
55 | - * @param array $headers |
|
56 | - * @param int $code |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - int $statusCode, |
|
62 | - string $message = null, |
|
63 | - Throwable $previous = null, |
|
64 | - array $headers = [], |
|
65 | - ?int $code = 0 |
|
66 | - ) { |
|
67 | - $this->headers = $headers; |
|
68 | - $this->code = $statusCode; |
|
49 | + /** |
|
50 | + * Initialize constructor. |
|
51 | + * |
|
52 | + * @param int $statusCode |
|
53 | + * @param string $message |
|
54 | + * @param \Throwable $previous |
|
55 | + * @param array $headers |
|
56 | + * @param int $code |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + int $statusCode, |
|
62 | + string $message = null, |
|
63 | + Throwable $previous = null, |
|
64 | + array $headers = [], |
|
65 | + ?int $code = 0 |
|
66 | + ) { |
|
67 | + $this->headers = $headers; |
|
68 | + $this->code = $statusCode; |
|
69 | 69 | |
70 | - parent::__construct($message, $code, $previous); |
|
71 | - } |
|
70 | + parent::__construct($message, $code, $previous); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Get Status Code headers. |
|
75 | - * |
|
76 | - * @return int |
|
77 | - */ |
|
78 | - public function getStatusCode() |
|
79 | - { |
|
80 | - return $this->code; |
|
81 | - } |
|
73 | + /** |
|
74 | + * Get Status Code headers. |
|
75 | + * |
|
76 | + * @return int |
|
77 | + */ |
|
78 | + public function getStatusCode() |
|
79 | + { |
|
80 | + return $this->code; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Get response headers. |
|
85 | - * |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - public function getHeaders() |
|
89 | - { |
|
90 | - return $this->headers; |
|
91 | - } |
|
83 | + /** |
|
84 | + * Get response headers. |
|
85 | + * |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + public function getHeaders() |
|
89 | + { |
|
90 | + return $this->headers; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Set response headers. |
|
95 | - * |
|
96 | - * @param array $headers Response headers |
|
97 | - * |
|
98 | - * @return mixed |
|
99 | - */ |
|
100 | - public function setHeaders(array $headers) |
|
101 | - { |
|
102 | - $this->headers = $headers; |
|
103 | - } |
|
93 | + /** |
|
94 | + * Set response headers. |
|
95 | + * |
|
96 | + * @param array $headers Response headers |
|
97 | + * |
|
98 | + * @return mixed |
|
99 | + */ |
|
100 | + public function setHeaders(array $headers) |
|
101 | + { |
|
102 | + $this->headers = $headers; |
|
103 | + } |
|
104 | 104 | } |
105 | 105 | \ No newline at end of file |
@@ -306,7 +306,7 @@ |
||
306 | 306 | */ |
307 | 307 | protected function renderExceptionWithGDebug(Throwable $e) |
308 | 308 | { |
309 | - return take(new GDebug, function ($debug) { |
|
309 | + return take(new GDebug, function($debug) { |
|
310 | 310 | |
311 | 311 | $debug->pushHandler($this->DebugHandler()); |
312 | 312 |
@@ -62,11 +62,11 @@ |
||
62 | 62 | */ |
63 | 63 | protected $locale; |
64 | 64 | |
65 | - /** |
|
66 | - * Boolean value whether the intl libraries exist on the system. |
|
67 | - * |
|
68 | - * @var bool $intlSupport |
|
69 | - */ |
|
65 | + /** |
|
66 | + * Boolean value whether the intl libraries exist on the system. |
|
67 | + * |
|
68 | + * @var bool $intlSupport |
|
69 | + */ |
|
70 | 70 | protected $intlSupport = false; |
71 | 71 | |
72 | 72 | /** |
@@ -254,7 +254,7 @@ |
||
254 | 254 | * |
255 | 255 | * @return string|bool |
256 | 256 | */ |
257 | - protected function formatMessage($line, array $replace = []): string|bool |
|
257 | + protected function formatMessage($line, array $replace = []): string | bool |
|
258 | 258 | { |
259 | 259 | if ( ! $this->intlSupport || ! count($replace)) { |
260 | 260 | return $line; |
@@ -170,7 +170,7 @@ |
||
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | - throw new ViewException(__('view.notFound', ['file' => $name])); |
|
173 | + throw new ViewException(__('view.notFound', ['file' => $name])); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -21,10 +21,13 @@ |
||
21 | 21 | <?php endforeach; ?> |
22 | 22 | </tbody> |
23 | 23 | </table> |
24 | - <?php else : ?> |
|
24 | + <?php else { |
|
25 | + : ?> |
|
25 | 26 | <label class="empty"><?= e($label) ?></label> |
26 | 27 | <span class="empty"><?= e(__('exception.empty')) ?></span> |
27 | - <?php endif; ?> |
|
28 | + <?php endif; |
|
29 | +} |
|
30 | +?> |
|
28 | 31 | </div> |
29 | 32 | <?php endforeach; ?> |
30 | 33 | </div> |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | <div class="frame-info-class"> |
13 | 13 | <?php if ($frame->getClass() == '') : ?> |
14 | 14 | <span class="frame-function"><?= e($frame->getFunction()) ?></span> |
15 | - <?php else: ?> |
|
15 | + <?php else { |
|
16 | + : ?> |
|
16 | 17 | <span class="frame-class"><?= e($frame->getClass()) ?></span> |
17 | 18 | <?php if ($frame->getFunction() != '') : ?> |
18 | 19 | <span class="frame-function"><?= e($frame->getFunction()) ?></span> |
@@ -26,5 +27,7 @@ discard block |
||
26 | 27 | </div> |
27 | 28 | |
28 | 29 | </div> |
29 | -<?php endforeach; ?> |
|
30 | +<?php endforeach; |
|
31 | +} |
|
32 | +?> |
|
30 | 33 | </div> |
31 | 34 | \ No newline at end of file |
@@ -259,7 +259,7 @@ |
||
259 | 259 | $quote = $value[0]; |
260 | 260 | |
261 | 261 | $regexPattern = sprintf( |
262 | - '/^ |
|
262 | + '/^ |
|
263 | 263 | %1$s # match a quote at the start of the value |
264 | 264 | ( # capturing sub-pattern used |
265 | 265 | (?: # we do not need to capture this |
@@ -274,7 +274,7 @@ |
||
274 | 274 | if (strpos($value, '$') !== false) { |
275 | 275 | $repository = $this->repository; |
276 | 276 | |
277 | - $value = preg_replace_callback('~\${([a-zA-Z0-9_]+)}~', function ($pattern) use ($repository) { |
|
277 | + $value = preg_replace_callback('~\${([a-zA-Z0-9_]+)}~', function($pattern) use ($repository) { |
|
278 | 278 | $nestedVariable = $repository->get($pattern[1]); |
279 | 279 | |
280 | 280 | if (is_null($nestedVariable)) { |
@@ -142,8 +142,7 @@ |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | $Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
145 | - } |
|
146 | - finally { |
|
145 | + } finally { |
|
147 | 146 | // Returns the contents of the output buffer |
148 | 147 | $output = $this->system->CleanOutputBuffer(); |
149 | 148 | } |
@@ -38,412 +38,412 @@ |
||
38 | 38 | */ |
39 | 39 | class GDebug implements DebugContract |
40 | 40 | { |
41 | - /** |
|
42 | - * Allow Handlers to force the script to quit. |
|
43 | - * |
|
44 | - * @var bool $allowQuit |
|
45 | - */ |
|
46 | - protected $allowQuit = true; |
|
41 | + /** |
|
42 | + * Allow Handlers to force the script to quit. |
|
43 | + * |
|
44 | + * @var bool $allowQuit |
|
45 | + */ |
|
46 | + protected $allowQuit = true; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Benchmark instance. |
|
50 | - * |
|
51 | - * @var string|object $benchmark |
|
52 | - */ |
|
53 | - protected $benchmark; |
|
54 | - |
|
55 | - /** |
|
56 | - * The handler stack. |
|
57 | - * |
|
58 | - * @var array $handlerStack |
|
59 | - */ |
|
60 | - protected $handlerStack = []; |
|
61 | - |
|
62 | - /** |
|
63 | - * The send Http code by default: 500 Internal Server Error. |
|
64 | - * |
|
65 | - * @var bool $sendHttpCode |
|
66 | - */ |
|
67 | - protected $sendHttpCode = 500; |
|
68 | - |
|
69 | - /** |
|
70 | - * The send output. |
|
71 | - * |
|
72 | - * @var bool $sendOutput |
|
73 | - */ |
|
74 | - protected $sendOutput = true; |
|
75 | - |
|
76 | - /** |
|
77 | - * The functions of system what control errors and exceptions. |
|
78 | - * |
|
79 | - * @var string|object $system |
|
80 | - */ |
|
81 | - protected $system; |
|
82 | - |
|
83 | - /** |
|
84 | - * In certain scenarios, like in shutdown handler, we can not throw exceptions. |
|
85 | - * |
|
86 | - * @var bool $throwExceptions |
|
87 | - */ |
|
88 | - protected $throwExceptions = true; |
|
89 | - |
|
90 | - /** |
|
91 | - * Constructor. The Debug class instance. |
|
92 | - * |
|
93 | - * @param \Syscodes\Components\Debug\Util\System|null $system |
|
94 | - * |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function __construct(System $system = null) |
|
98 | - { |
|
99 | - $this->system = $system ?: new System; |
|
100 | - $this->benchmark = new Benchmark; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
105 | - * error, display it if display_errors is on, and fire an event that allows custom actions |
|
106 | - * to be taken at this point. |
|
107 | - * |
|
108 | - * @param \Throwable $exception |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function handleException(Throwable $exception): string |
|
113 | - { |
|
114 | - // The start benchmark |
|
115 | - $this->benchmark->start('total_execution', LENEVOR_START); |
|
116 | - |
|
117 | - $supervisor = $this->getSupervisor($exception); |
|
118 | - |
|
119 | - // Start buffer |
|
120 | - $this->system->startOutputBuferring(); |
|
121 | - |
|
122 | - $handlerResponse = null; |
|
123 | - $handlerContentType = null; |
|
48 | + /** |
|
49 | + * Benchmark instance. |
|
50 | + * |
|
51 | + * @var string|object $benchmark |
|
52 | + */ |
|
53 | + protected $benchmark; |
|
54 | + |
|
55 | + /** |
|
56 | + * The handler stack. |
|
57 | + * |
|
58 | + * @var array $handlerStack |
|
59 | + */ |
|
60 | + protected $handlerStack = []; |
|
61 | + |
|
62 | + /** |
|
63 | + * The send Http code by default: 500 Internal Server Error. |
|
64 | + * |
|
65 | + * @var bool $sendHttpCode |
|
66 | + */ |
|
67 | + protected $sendHttpCode = 500; |
|
68 | + |
|
69 | + /** |
|
70 | + * The send output. |
|
71 | + * |
|
72 | + * @var bool $sendOutput |
|
73 | + */ |
|
74 | + protected $sendOutput = true; |
|
75 | + |
|
76 | + /** |
|
77 | + * The functions of system what control errors and exceptions. |
|
78 | + * |
|
79 | + * @var string|object $system |
|
80 | + */ |
|
81 | + protected $system; |
|
82 | + |
|
83 | + /** |
|
84 | + * In certain scenarios, like in shutdown handler, we can not throw exceptions. |
|
85 | + * |
|
86 | + * @var bool $throwExceptions |
|
87 | + */ |
|
88 | + protected $throwExceptions = true; |
|
89 | + |
|
90 | + /** |
|
91 | + * Constructor. The Debug class instance. |
|
92 | + * |
|
93 | + * @param \Syscodes\Components\Debug\Util\System|null $system |
|
94 | + * |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public function __construct(System $system = null) |
|
98 | + { |
|
99 | + $this->system = $system ?: new System; |
|
100 | + $this->benchmark = new Benchmark; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
105 | + * error, display it if display_errors is on, and fire an event that allows custom actions |
|
106 | + * to be taken at this point. |
|
107 | + * |
|
108 | + * @param \Throwable $exception |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function handleException(Throwable $exception): string |
|
113 | + { |
|
114 | + // The start benchmark |
|
115 | + $this->benchmark->start('total_execution', LENEVOR_START); |
|
116 | + |
|
117 | + $supervisor = $this->getSupervisor($exception); |
|
118 | + |
|
119 | + // Start buffer |
|
120 | + $this->system->startOutputBuferring(); |
|
121 | + |
|
122 | + $handlerResponse = null; |
|
123 | + $handlerContentType = null; |
|
124 | 124 | |
125 | - try { |
|
126 | - foreach ($this->handlerStack as $handler) { |
|
127 | - $handler->setDebug($this); |
|
128 | - $handler->setException($exception); |
|
129 | - $handler->setSupervisor($supervisor); |
|
125 | + try { |
|
126 | + foreach ($this->handlerStack as $handler) { |
|
127 | + $handler->setDebug($this); |
|
128 | + $handler->setException($exception); |
|
129 | + $handler->setSupervisor($supervisor); |
|
130 | 130 | |
131 | - $handlerResponse = $handler->handle(); |
|
131 | + $handlerResponse = $handler->handle(); |
|
132 | 132 | |
133 | - // Collect the content type for possible sending in the headers |
|
134 | - $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; |
|
133 | + // Collect the content type for possible sending in the headers |
|
134 | + $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; |
|
135 | 135 | |
136 | - if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) { |
|
137 | - break; |
|
138 | - } |
|
139 | - } |
|
136 | + if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) { |
|
137 | + break; |
|
138 | + } |
|
139 | + } |
|
140 | 140 | |
141 | - $Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
|
142 | - } |
|
143 | - finally { |
|
144 | - // Returns the contents of the output buffer |
|
145 | - $output = $this->system->CleanOutputBuffer(); |
|
146 | - } |
|
147 | - |
|
148 | - // Returns the contents of the output buffer for loading time of page |
|
149 | - $totalTime = $this->benchmark->getElapsedTime('total_execution'); |
|
150 | - $output = str_replace('{elapsed_time}', $totalTime, $output); |
|
151 | - |
|
152 | - if ($this->writeToOutput()) { |
|
153 | - if ($Quit) { |
|
154 | - while ($this->system->getOutputBufferLevel() > 0) { |
|
155 | - // Cleanes the output buffer |
|
156 | - $this->system->endOutputBuffering(); |
|
157 | - } |
|
158 | - |
|
159 | - if (Misc::sendHeaders() && $handlerContentType) { |
|
160 | - header("Content-Type: {$handlerContentType}"); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - $this->writeToOutputBuffer($output); |
|
165 | - } |
|
166 | - |
|
167 | - if ($Quit) { |
|
168 | - $this->system->flushOutputBuffer(); |
|
169 | - $this->system->stopException(1); |
|
170 | - } |
|
171 | - |
|
172 | - return $output; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Allow Handlers to force the script to quit. |
|
177 | - * |
|
178 | - * @param bool|int|null $exit |
|
179 | - * |
|
180 | - * @return bool |
|
181 | - */ |
|
182 | - public function allowQuit($exit = null): bool |
|
183 | - { |
|
184 | - if (func_num_args() == 0) { |
|
185 | - return $this->allowQuit; |
|
186 | - } |
|
187 | - |
|
188 | - return $this->allowQuit = (bool) $exit; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Lenevor Exception push output directly to the client it the data |
|
193 | - * if they are true, but if it is false, the output will be returned |
|
194 | - * by exception. |
|
195 | - * |
|
196 | - * @param bool|int|null $send |
|
197 | - * |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function writeToOutput($send = null): bool |
|
201 | - { |
|
202 | - if (func_num_args() == 0) { |
|
203 | - return $this->sendOutput; |
|
204 | - } |
|
141 | + $Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
|
142 | + } |
|
143 | + finally { |
|
144 | + // Returns the contents of the output buffer |
|
145 | + $output = $this->system->CleanOutputBuffer(); |
|
146 | + } |
|
147 | + |
|
148 | + // Returns the contents of the output buffer for loading time of page |
|
149 | + $totalTime = $this->benchmark->getElapsedTime('total_execution'); |
|
150 | + $output = str_replace('{elapsed_time}', $totalTime, $output); |
|
151 | + |
|
152 | + if ($this->writeToOutput()) { |
|
153 | + if ($Quit) { |
|
154 | + while ($this->system->getOutputBufferLevel() > 0) { |
|
155 | + // Cleanes the output buffer |
|
156 | + $this->system->endOutputBuffering(); |
|
157 | + } |
|
158 | + |
|
159 | + if (Misc::sendHeaders() && $handlerContentType) { |
|
160 | + header("Content-Type: {$handlerContentType}"); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + $this->writeToOutputBuffer($output); |
|
165 | + } |
|
166 | + |
|
167 | + if ($Quit) { |
|
168 | + $this->system->flushOutputBuffer(); |
|
169 | + $this->system->stopException(1); |
|
170 | + } |
|
171 | + |
|
172 | + return $output; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Allow Handlers to force the script to quit. |
|
177 | + * |
|
178 | + * @param bool|int|null $exit |
|
179 | + * |
|
180 | + * @return bool |
|
181 | + */ |
|
182 | + public function allowQuit($exit = null): bool |
|
183 | + { |
|
184 | + if (func_num_args() == 0) { |
|
185 | + return $this->allowQuit; |
|
186 | + } |
|
187 | + |
|
188 | + return $this->allowQuit = (bool) $exit; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Lenevor Exception push output directly to the client it the data |
|
193 | + * if they are true, but if it is false, the output will be returned |
|
194 | + * by exception. |
|
195 | + * |
|
196 | + * @param bool|int|null $send |
|
197 | + * |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function writeToOutput($send = null): bool |
|
201 | + { |
|
202 | + if (func_num_args() == 0) { |
|
203 | + return $this->sendOutput; |
|
204 | + } |
|
205 | 205 | |
206 | - return $this->sendOutput = (bool) $send; |
|
207 | - } |
|
206 | + return $this->sendOutput = (bool) $send; |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Generate output to the browser. |
|
211 | - * |
|
212 | - * @param string $output |
|
213 | - * |
|
214 | - * @return static |
|
215 | - */ |
|
216 | - protected function writeToOutputBuffer($output): static |
|
217 | - { |
|
218 | - if ($this->sendHttpCode() && Misc::sendHeaders()) { |
|
219 | - $this->system->setHttpResponseCode($this->sendHttpCode()); |
|
220 | - } |
|
209 | + /** |
|
210 | + * Generate output to the browser. |
|
211 | + * |
|
212 | + * @param string $output |
|
213 | + * |
|
214 | + * @return static |
|
215 | + */ |
|
216 | + protected function writeToOutputBuffer($output): static |
|
217 | + { |
|
218 | + if ($this->sendHttpCode() && Misc::sendHeaders()) { |
|
219 | + $this->system->setHttpResponseCode($this->sendHttpCode()); |
|
220 | + } |
|
221 | 221 | |
222 | - echo $output; |
|
222 | + echo $output; |
|
223 | 223 | |
224 | - return $this; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Error handler |
|
229 | - * |
|
230 | - * This will catch the php native error and treat it as a exception which will |
|
231 | - * provide a full back trace on all errors. |
|
232 | - * |
|
233 | - * @param int $level |
|
234 | - * @param string $message |
|
235 | - * @param string|null $file |
|
236 | - * @param int|null $line |
|
237 | - * |
|
238 | - * @return bool |
|
239 | - * |
|
240 | - * @throws \ErrorException |
|
241 | - */ |
|
242 | - public function handleError( |
|
243 | - int $level, |
|
244 | - string $message, |
|
245 | - string $file = null, |
|
246 | - int $line = null |
|
247 | - ): bool { |
|
248 | - if ($level & $this->system->getErrorReportingLevel()) { |
|
249 | - $exception = new ErrorException($message, $level, $level, $file, $line); |
|
250 | - |
|
251 | - if ($this->throwExceptions) { |
|
252 | - throw $exception; |
|
253 | - } else { |
|
254 | - $this->handleException($exception); |
|
255 | - } |
|
256 | - |
|
257 | - return true; |
|
258 | - } |
|
259 | - |
|
260 | - return false; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Pushes a handler to the end of the stack. |
|
265 | - * |
|
266 | - * @param string|callable $handler |
|
267 | - * |
|
268 | - * @return \Syscodes\Components\Contracts\Debug\Handler |
|
269 | - */ |
|
270 | - public function pushHandler($handler) |
|
271 | - { |
|
272 | - return $this->prependHandler($handler); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Appends a handler to the end of the stack. |
|
277 | - * |
|
278 | - * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
279 | - * |
|
280 | - * @return static |
|
281 | - */ |
|
282 | - public function appendHandler($handler): static |
|
283 | - { |
|
284 | - array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
285 | - |
|
286 | - return $this; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Prepends a handler to the start of the stack. |
|
291 | - * |
|
292 | - * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
293 | - * |
|
294 | - * @return static |
|
295 | - */ |
|
296 | - public function prependHandler($handler): static |
|
297 | - { |
|
298 | - array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
299 | - |
|
300 | - return $this; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Create a CallbackHandler from callable and throw if handler is invalid. |
|
305 | - * |
|
306 | - * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
307 | - * |
|
308 | - * @return \Syscodes\Components\Contracts\Debug\Handler |
|
309 | - * |
|
310 | - * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Components\Contracts\Debug\Handler |
|
311 | - */ |
|
312 | - protected function resolveHandler($handler) |
|
313 | - { |
|
314 | - if (is_callable($handler)) { |
|
315 | - $handler = new CallbackHandler($handler); |
|
316 | - } |
|
317 | - |
|
318 | - if ( ! $handler instanceof MainHandler) { |
|
319 | - throw new InvalidArgumentException( |
|
320 | - "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
321 | - "Syscodes\Components\\Contracts\\Debug\\Handler" |
|
322 | - ); |
|
323 | - } |
|
324 | - |
|
325 | - return $handler; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns an array with all handlers, in the order they were added to the stack. |
|
330 | - * |
|
331 | - * @return array |
|
332 | - */ |
|
333 | - public function getHandlers(): array |
|
334 | - { |
|
335 | - return $this->handlerStack; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Clears all handlers in the handlerStack, including the default PleasingPage handler. |
|
340 | - * |
|
341 | - * @return static |
|
342 | - */ |
|
343 | - public function clearHandlers(): static |
|
344 | - { |
|
345 | - $this->handlerStack = []; |
|
346 | - |
|
347 | - return $this; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Removes the last handler in the stack and returns it. |
|
352 | - * |
|
353 | - * @return array|null |
|
354 | - */ |
|
355 | - public function popHandler() |
|
356 | - { |
|
357 | - return array_pop($this->handlerStack); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Gets supervisor already specified. |
|
362 | - * |
|
363 | - * @param \Throwable $exception |
|
364 | - * |
|
365 | - * @return \Syscodes\Components\Debug\Engine\Supervisor |
|
366 | - */ |
|
367 | - protected function getSupervisor(Throwable $exception) |
|
368 | - { |
|
369 | - return new Supervisor($exception); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Unregisters all handlers registered by this Debug instance. |
|
374 | - * |
|
375 | - * @return void |
|
376 | - */ |
|
377 | - public function off(): void |
|
378 | - { |
|
379 | - $this->system->restoreExceptionHandler(); |
|
380 | - $this->system->restoreErrorHandler(); |
|
381 | - } |
|
224 | + return $this; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Error handler |
|
229 | + * |
|
230 | + * This will catch the php native error and treat it as a exception which will |
|
231 | + * provide a full back trace on all errors. |
|
232 | + * |
|
233 | + * @param int $level |
|
234 | + * @param string $message |
|
235 | + * @param string|null $file |
|
236 | + * @param int|null $line |
|
237 | + * |
|
238 | + * @return bool |
|
239 | + * |
|
240 | + * @throws \ErrorException |
|
241 | + */ |
|
242 | + public function handleError( |
|
243 | + int $level, |
|
244 | + string $message, |
|
245 | + string $file = null, |
|
246 | + int $line = null |
|
247 | + ): bool { |
|
248 | + if ($level & $this->system->getErrorReportingLevel()) { |
|
249 | + $exception = new ErrorException($message, $level, $level, $file, $line); |
|
250 | + |
|
251 | + if ($this->throwExceptions) { |
|
252 | + throw $exception; |
|
253 | + } else { |
|
254 | + $this->handleException($exception); |
|
255 | + } |
|
256 | + |
|
257 | + return true; |
|
258 | + } |
|
259 | + |
|
260 | + return false; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Pushes a handler to the end of the stack. |
|
265 | + * |
|
266 | + * @param string|callable $handler |
|
267 | + * |
|
268 | + * @return \Syscodes\Components\Contracts\Debug\Handler |
|
269 | + */ |
|
270 | + public function pushHandler($handler) |
|
271 | + { |
|
272 | + return $this->prependHandler($handler); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Appends a handler to the end of the stack. |
|
277 | + * |
|
278 | + * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
279 | + * |
|
280 | + * @return static |
|
281 | + */ |
|
282 | + public function appendHandler($handler): static |
|
283 | + { |
|
284 | + array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
285 | + |
|
286 | + return $this; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Prepends a handler to the start of the stack. |
|
291 | + * |
|
292 | + * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
293 | + * |
|
294 | + * @return static |
|
295 | + */ |
|
296 | + public function prependHandler($handler): static |
|
297 | + { |
|
298 | + array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
299 | + |
|
300 | + return $this; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Create a CallbackHandler from callable and throw if handler is invalid. |
|
305 | + * |
|
306 | + * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
307 | + * |
|
308 | + * @return \Syscodes\Components\Contracts\Debug\Handler |
|
309 | + * |
|
310 | + * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Components\Contracts\Debug\Handler |
|
311 | + */ |
|
312 | + protected function resolveHandler($handler) |
|
313 | + { |
|
314 | + if (is_callable($handler)) { |
|
315 | + $handler = new CallbackHandler($handler); |
|
316 | + } |
|
317 | + |
|
318 | + if ( ! $handler instanceof MainHandler) { |
|
319 | + throw new InvalidArgumentException( |
|
320 | + "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
321 | + "Syscodes\Components\\Contracts\\Debug\\Handler" |
|
322 | + ); |
|
323 | + } |
|
324 | + |
|
325 | + return $handler; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns an array with all handlers, in the order they were added to the stack. |
|
330 | + * |
|
331 | + * @return array |
|
332 | + */ |
|
333 | + public function getHandlers(): array |
|
334 | + { |
|
335 | + return $this->handlerStack; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Clears all handlers in the handlerStack, including the default PleasingPage handler. |
|
340 | + * |
|
341 | + * @return static |
|
342 | + */ |
|
343 | + public function clearHandlers(): static |
|
344 | + { |
|
345 | + $this->handlerStack = []; |
|
346 | + |
|
347 | + return $this; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Removes the last handler in the stack and returns it. |
|
352 | + * |
|
353 | + * @return array|null |
|
354 | + */ |
|
355 | + public function popHandler() |
|
356 | + { |
|
357 | + return array_pop($this->handlerStack); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Gets supervisor already specified. |
|
362 | + * |
|
363 | + * @param \Throwable $exception |
|
364 | + * |
|
365 | + * @return \Syscodes\Components\Debug\Engine\Supervisor |
|
366 | + */ |
|
367 | + protected function getSupervisor(Throwable $exception) |
|
368 | + { |
|
369 | + return new Supervisor($exception); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Unregisters all handlers registered by this Debug instance. |
|
374 | + * |
|
375 | + * @return void |
|
376 | + */ |
|
377 | + public function off(): void |
|
378 | + { |
|
379 | + $this->system->restoreExceptionHandler(); |
|
380 | + $this->system->restoreErrorHandler(); |
|
381 | + } |
|
382 | 382 | |
383 | - /** |
|
384 | - * Registers this instance as an error handler. |
|
385 | - * |
|
386 | - * @return void |
|
387 | - */ |
|
388 | - public function on() : void |
|
389 | - { |
|
390 | - // Set the exception handler |
|
391 | - $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]); |
|
392 | - // Set the error handler |
|
393 | - $this->system->setErrorHandler([$this, self::ERROR_HANDLER]); |
|
394 | - // Set the handler for shutdown to catch Parse errors |
|
395 | - $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
400 | - * to use 502, 503, or another 5xx family code. |
|
401 | - * |
|
402 | - * @param bool|int $code |
|
403 | - * |
|
404 | - * @return int|false |
|
405 | - * |
|
406 | - * @throws \InvalidArgumentException |
|
407 | - */ |
|
408 | - public function sendHttpCode($code = null) |
|
409 | - { |
|
410 | - if (func_num_args() == 0) { |
|
411 | - return $this->sendHttpCode; |
|
412 | - } |
|
383 | + /** |
|
384 | + * Registers this instance as an error handler. |
|
385 | + * |
|
386 | + * @return void |
|
387 | + */ |
|
388 | + public function on() : void |
|
389 | + { |
|
390 | + // Set the exception handler |
|
391 | + $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]); |
|
392 | + // Set the error handler |
|
393 | + $this->system->setErrorHandler([$this, self::ERROR_HANDLER]); |
|
394 | + // Set the handler for shutdown to catch Parse errors |
|
395 | + $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
400 | + * to use 502, 503, or another 5xx family code. |
|
401 | + * |
|
402 | + * @param bool|int $code |
|
403 | + * |
|
404 | + * @return int|false |
|
405 | + * |
|
406 | + * @throws \InvalidArgumentException |
|
407 | + */ |
|
408 | + public function sendHttpCode($code = null) |
|
409 | + { |
|
410 | + if (func_num_args() == 0) { |
|
411 | + return $this->sendHttpCode; |
|
412 | + } |
|
413 | 413 | |
414 | - if ( ! $code) { |
|
415 | - return $this->sendHttpCode = false; |
|
416 | - } |
|
414 | + if ( ! $code) { |
|
415 | + return $this->sendHttpCode = false; |
|
416 | + } |
|
417 | 417 | |
418 | - if ($code === true) { |
|
419 | - $code = 500; |
|
420 | - } |
|
418 | + if ($code === true) { |
|
419 | + $code = 500; |
|
420 | + } |
|
421 | 421 | |
422 | - if ($code < 400 || 600 <= $code) { |
|
423 | - throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx"); |
|
424 | - } |
|
422 | + if ($code < 400 || 600 <= $code) { |
|
423 | + throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx"); |
|
424 | + } |
|
425 | 425 | |
426 | - return $this->sendHttpCode = $code; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * This will catch errors that are generated at the shutdown level of execution. |
|
431 | - * |
|
432 | - * @return void |
|
433 | - * |
|
434 | - * @throws \ErrorException |
|
435 | - */ |
|
436 | - public function handleShutdown() |
|
437 | - { |
|
438 | - $this->throwExceptions = false; |
|
439 | - |
|
440 | - $error = $this->system->getLastError(); |
|
441 | - |
|
442 | - // If we've got an error that hasn't been displayed, then convert |
|
443 | - // it to an Exception and use the Exception handler to display it |
|
444 | - // to the user |
|
445 | - if ($error && Misc::isFatalError($error['type'])) { |
|
446 | - $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
|
447 | - } |
|
448 | - } |
|
426 | + return $this->sendHttpCode = $code; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * This will catch errors that are generated at the shutdown level of execution. |
|
431 | + * |
|
432 | + * @return void |
|
433 | + * |
|
434 | + * @throws \ErrorException |
|
435 | + */ |
|
436 | + public function handleShutdown() |
|
437 | + { |
|
438 | + $this->throwExceptions = false; |
|
439 | + |
|
440 | + $error = $this->system->getLastError(); |
|
441 | + |
|
442 | + // If we've got an error that hasn't been displayed, then convert |
|
443 | + // it to an Exception and use the Exception handler to display it |
|
444 | + // to the user |
|
445 | + if ($error && Misc::isFatalError($error['type'])) { |
|
446 | + $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
|
447 | + } |
|
448 | + } |
|
449 | 449 | } |
450 | 450 | \ No newline at end of file |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $this->system->endOutputBuffering(); |
157 | 157 | } |
158 | 158 | |
159 | - if (Misc::sendHeaders() && $handlerContentType) { |
|
159 | + if (Misc::sendHeaders() && $handlerContentType) { |
|
160 | 160 | header("Content-Type: {$handlerContentType}"); |
161 | 161 | } |
162 | 162 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | |
318 | 318 | if ( ! $handler instanceof MainHandler) { |
319 | 319 | throw new InvalidArgumentException( |
320 | - "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
320 | + "Argument to ".__METHOD__." must be a callable, or instance of ". |
|
321 | 321 | "Syscodes\Components\\Contracts\\Debug\\Handler" |
322 | 322 | ); |
323 | 323 | } |