@@ -39,274 +39,274 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class Lenevor implements LenevorContract |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * The application implementation. |
|
| 44 | - * |
|
| 45 | - * @var \Syscodes\Contracts\Core\Application $app |
|
| 46 | - */ |
|
| 47 | - protected $app; |
|
| 42 | + /** |
|
| 43 | + * The application implementation. |
|
| 44 | + * |
|
| 45 | + * @var \Syscodes\Contracts\Core\Application $app |
|
| 46 | + */ |
|
| 47 | + protected $app; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The bootstrap classes for the application. |
|
| 51 | - * |
|
| 52 | - * @var array $bootstrappers |
|
| 53 | - */ |
|
| 54 | - protected $bootstrappers = [ |
|
| 55 | - \Syscodes\Core\Bootstrap\BootDetectEnvironment::class, |
|
| 56 | - \Syscodes\Core\Bootstrap\BootConfiguration::class, |
|
| 57 | - \Syscodes\Core\Bootstrap\BootHandleExceptions::class, |
|
| 58 | - \Syscodes\Core\Bootstrap\BootRegisterFacades::class, |
|
| 59 | - \Syscodes\Core\Bootstrap\BootRegisterProviders::class, |
|
| 60 | - \Syscodes\Core\Bootstrap\BootProviders::class, |
|
| 61 | - ]; |
|
| 49 | + /** |
|
| 50 | + * The bootstrap classes for the application. |
|
| 51 | + * |
|
| 52 | + * @var array $bootstrappers |
|
| 53 | + */ |
|
| 54 | + protected $bootstrappers = [ |
|
| 55 | + \Syscodes\Core\Bootstrap\BootDetectEnvironment::class, |
|
| 56 | + \Syscodes\Core\Bootstrap\BootConfiguration::class, |
|
| 57 | + \Syscodes\Core\Bootstrap\BootHandleExceptions::class, |
|
| 58 | + \Syscodes\Core\Bootstrap\BootRegisterFacades::class, |
|
| 59 | + \Syscodes\Core\Bootstrap\BootRegisterProviders::class, |
|
| 60 | + \Syscodes\Core\Bootstrap\BootProviders::class, |
|
| 61 | + ]; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Get the application's middleware. |
|
| 65 | - * |
|
| 66 | - * @var array $middleware |
|
| 67 | - */ |
|
| 68 | - protected $middleware = []; |
|
| 63 | + /** |
|
| 64 | + * Get the application's middleware. |
|
| 65 | + * |
|
| 66 | + * @var array $middleware |
|
| 67 | + */ |
|
| 68 | + protected $middleware = []; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Get the application's middleware groups. |
|
| 72 | - * |
|
| 73 | - * @var array $middlewareGroups |
|
| 74 | - */ |
|
| 75 | - protected $middlewareGroups = []; |
|
| 70 | + /** |
|
| 71 | + * Get the application's middleware groups. |
|
| 72 | + * |
|
| 73 | + * @var array $middlewareGroups |
|
| 74 | + */ |
|
| 75 | + protected $middlewareGroups = []; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The router instance. |
|
| 79 | - * |
|
| 80 | - * @var \Syscodes\Routing\Router $router |
|
| 81 | - */ |
|
| 82 | - protected $router; |
|
| 77 | + /** |
|
| 78 | + * The router instance. |
|
| 79 | + * |
|
| 80 | + * @var \Syscodes\Routing\Router $router |
|
| 81 | + */ |
|
| 82 | + protected $router; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Get the application's route middleware. |
|
| 86 | - * |
|
| 87 | - * @var array $routeMiddleware |
|
| 88 | - */ |
|
| 89 | - protected $routeMiddleware = []; |
|
| 84 | + /** |
|
| 85 | + * Get the application's route middleware. |
|
| 86 | + * |
|
| 87 | + * @var array $routeMiddleware |
|
| 88 | + */ |
|
| 89 | + protected $routeMiddleware = []; |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Total app execution time. |
|
| 93 | - * |
|
| 94 | - * @var float $totalTime |
|
| 95 | - */ |
|
| 96 | - protected $totalTime; |
|
| 91 | + /** |
|
| 92 | + * Total app execution time. |
|
| 93 | + * |
|
| 94 | + * @var float $totalTime |
|
| 95 | + */ |
|
| 96 | + protected $totalTime; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Constructor. Lenevor class instance. |
|
| 100 | - * |
|
| 101 | - * @param \Syscodes\Contracts\Core\Application $app |
|
| 102 | - * @param \Syscodes\Routing\Router $router |
|
| 103 | - * |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - public function __construct(Application $app, Router $router) |
|
| 107 | - { |
|
| 108 | - $this->app = $app; |
|
| 109 | - $this->router = $router; |
|
| 98 | + /** |
|
| 99 | + * Constructor. Lenevor class instance. |
|
| 100 | + * |
|
| 101 | + * @param \Syscodes\Contracts\Core\Application $app |
|
| 102 | + * @param \Syscodes\Routing\Router $router |
|
| 103 | + * |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + public function __construct(Application $app, Router $router) |
|
| 107 | + { |
|
| 108 | + $this->app = $app; |
|
| 109 | + $this->router = $router; |
|
| 110 | 110 | |
| 111 | - $this->syncMiddlewareRoute(); |
|
| 112 | - } |
|
| 111 | + $this->syncMiddlewareRoute(); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Initializes the framework, this can only be called once. |
|
| 116 | - * Launch the application. |
|
| 117 | - * |
|
| 118 | - * @param \Syscodes\http\Request $request |
|
| 119 | - * |
|
| 120 | - * @return \Syscodes\Http\Response |
|
| 121 | - */ |
|
| 122 | - public function handle($request) |
|
| 123 | - { |
|
| 124 | - try { |
|
| 125 | - $response = $this->sendRequestThroughRouter($request); |
|
| 126 | - } catch (Throwable $e) { |
|
| 127 | - $this->reportException($e); |
|
| 114 | + /** |
|
| 115 | + * Initializes the framework, this can only be called once. |
|
| 116 | + * Launch the application. |
|
| 117 | + * |
|
| 118 | + * @param \Syscodes\http\Request $request |
|
| 119 | + * |
|
| 120 | + * @return \Syscodes\Http\Response |
|
| 121 | + */ |
|
| 122 | + public function handle($request) |
|
| 123 | + { |
|
| 124 | + try { |
|
| 125 | + $response = $this->sendRequestThroughRouter($request); |
|
| 126 | + } catch (Throwable $e) { |
|
| 127 | + $this->reportException($e); |
|
| 128 | 128 | |
| 129 | - $response = $this->renderException($request, $e); |
|
| 130 | - } |
|
| 129 | + $response = $this->renderException($request, $e); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - return $response; |
|
| 133 | - } |
|
| 132 | + return $response; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Send the given request through the router. |
|
| 137 | - * |
|
| 138 | - * @param \Syscodes\Http\Request $request |
|
| 139 | - * |
|
| 140 | - * @return \Syscodes\Http\Response |
|
| 141 | - */ |
|
| 142 | - protected function sendRequestThroughRouter($request) |
|
| 143 | - { |
|
| 144 | - $this->app->instance('request', $request); |
|
| 135 | + /** |
|
| 136 | + * Send the given request through the router. |
|
| 137 | + * |
|
| 138 | + * @param \Syscodes\Http\Request $request |
|
| 139 | + * |
|
| 140 | + * @return \Syscodes\Http\Response |
|
| 141 | + */ |
|
| 142 | + protected function sendRequestThroughRouter($request) |
|
| 143 | + { |
|
| 144 | + $this->app->instance('request', $request); |
|
| 145 | 145 | |
| 146 | - Facade::clearResolvedInstance('request'); |
|
| 146 | + Facade::clearResolvedInstance('request'); |
|
| 147 | 147 | |
| 148 | - // Load configuration system |
|
| 149 | - $this->bootstrap(); |
|
| 148 | + // Load configuration system |
|
| 149 | + $this->bootstrap(); |
|
| 150 | 150 | |
| 151 | - return (new Pipeline($this->app)) |
|
| 152 | - ->send($request) |
|
| 153 | - ->through($this->app->skipGoingMiddleware() ? [] : $this->middleware) |
|
| 154 | - ->then($this->dispatchToRouter()); |
|
| 155 | - } |
|
| 151 | + return (new Pipeline($this->app)) |
|
| 152 | + ->send($request) |
|
| 153 | + ->through($this->app->skipGoingMiddleware() ? [] : $this->middleware) |
|
| 154 | + ->then($this->dispatchToRouter()); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Bootstrap the application for HTTP requests. |
|
| 159 | - * |
|
| 160 | - * @return void |
|
| 161 | - */ |
|
| 162 | - protected function bootstrap() |
|
| 163 | - { |
|
| 164 | - if ( ! $this->app->hasBeenBootstrapped()) { |
|
| 165 | - $this->app->bootstrapWith($this->bootstrappers()); |
|
| 166 | - } |
|
| 157 | + /** |
|
| 158 | + * Bootstrap the application for HTTP requests. |
|
| 159 | + * |
|
| 160 | + * @return void |
|
| 161 | + */ |
|
| 162 | + protected function bootstrap() |
|
| 163 | + { |
|
| 164 | + if ( ! $this->app->hasBeenBootstrapped()) { |
|
| 165 | + $this->app->bootstrapWith($this->bootstrappers()); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $this->app->loadDeferredProviders(); |
|
| 169 | - } |
|
| 168 | + $this->app->loadDeferredProviders(); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Get the bootstrap classes for the application. |
|
| 173 | - * |
|
| 174 | - * @return array |
|
| 175 | - */ |
|
| 176 | - protected function bootstrappers() |
|
| 177 | - { |
|
| 178 | - return $this->bootstrappers; |
|
| 179 | - } |
|
| 171 | + /** |
|
| 172 | + * Get the bootstrap classes for the application. |
|
| 173 | + * |
|
| 174 | + * @return array |
|
| 175 | + */ |
|
| 176 | + protected function bootstrappers() |
|
| 177 | + { |
|
| 178 | + return $this->bootstrappers; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Sync the current state of the middleware to the router. |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - protected function syncMiddlewareRoute() |
|
| 187 | - { |
|
| 188 | - foreach ($this->middlewareGroups as $key => $middleware) { |
|
| 189 | - $this->router->middlewareGroup($key, $middleware); |
|
| 190 | - } |
|
| 181 | + /** |
|
| 182 | + * Sync the current state of the middleware to the router. |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + protected function syncMiddlewareRoute() |
|
| 187 | + { |
|
| 188 | + foreach ($this->middlewareGroups as $key => $middleware) { |
|
| 189 | + $this->router->middlewareGroup($key, $middleware); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - foreach ($this->routeMiddleware as $key => $middleware) { |
|
| 193 | - $this->router->aliasMiddleware($key, $middleware); |
|
| 194 | - } |
|
| 195 | - } |
|
| 192 | + foreach ($this->routeMiddleware as $key => $middleware) { |
|
| 193 | + $this->router->aliasMiddleware($key, $middleware); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Get the dispatcher of routes. |
|
| 199 | - * |
|
| 200 | - * @return \Closure |
|
| 201 | - */ |
|
| 202 | - protected function dispatchToRouter() |
|
| 203 | - { |
|
| 204 | - return function ($request) { |
|
| 205 | - $this->app->instance('request', $request); |
|
| 197 | + /** |
|
| 198 | + * Get the dispatcher of routes. |
|
| 199 | + * |
|
| 200 | + * @return \Closure |
|
| 201 | + */ |
|
| 202 | + protected function dispatchToRouter() |
|
| 203 | + { |
|
| 204 | + return function ($request) { |
|
| 205 | + $this->app->instance('request', $request); |
|
| 206 | 206 | |
| 207 | - return $this->router->dispatch($request); |
|
| 208 | - }; |
|
| 209 | - } |
|
| 207 | + return $this->router->dispatch($request); |
|
| 208 | + }; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * Call the shutdown method on any terminable middleware. |
|
| 213 | - * |
|
| 214 | - * @param \Syscodes\Http\Request $request |
|
| 215 | - * @param \Syscodes\Http\Response $response |
|
| 216 | - * |
|
| 217 | - * @return void |
|
| 218 | - */ |
|
| 219 | - public function shutdown($request, $response) |
|
| 220 | - { |
|
| 221 | - $this->shutdownMiddleware($request, $response); |
|
| 222 | - } |
|
| 211 | + /** |
|
| 212 | + * Call the shutdown method on any terminable middleware. |
|
| 213 | + * |
|
| 214 | + * @param \Syscodes\Http\Request $request |
|
| 215 | + * @param \Syscodes\Http\Response $response |
|
| 216 | + * |
|
| 217 | + * @return void |
|
| 218 | + */ |
|
| 219 | + public function shutdown($request, $response) |
|
| 220 | + { |
|
| 221 | + $this->shutdownMiddleware($request, $response); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Call the terminate method on any terminable middleware. |
|
| 226 | - * |
|
| 227 | - * @param \Syscodes\Http\Request $request |
|
| 228 | - * @param \Syscodes\Http\Response $response |
|
| 229 | - * |
|
| 230 | - * @return void |
|
| 231 | - */ |
|
| 232 | - protected function shutdownMiddleware($request, $response) |
|
| 233 | - { |
|
| 234 | - $middlewares = $this->app->skipGoingMiddleware() ? [] : array_merge( |
|
| 235 | - $this->gatherRouteMiddleware($request), |
|
| 236 | - $this->middleware |
|
| 237 | - ); |
|
| 224 | + /** |
|
| 225 | + * Call the terminate method on any terminable middleware. |
|
| 226 | + * |
|
| 227 | + * @param \Syscodes\Http\Request $request |
|
| 228 | + * @param \Syscodes\Http\Response $response |
|
| 229 | + * |
|
| 230 | + * @return void |
|
| 231 | + */ |
|
| 232 | + protected function shutdownMiddleware($request, $response) |
|
| 233 | + { |
|
| 234 | + $middlewares = $this->app->skipGoingMiddleware() ? [] : array_merge( |
|
| 235 | + $this->gatherRouteMiddleware($request), |
|
| 236 | + $this->middleware |
|
| 237 | + ); |
|
| 238 | 238 | |
| 239 | - foreach ($middlewares as $middleware) { |
|
| 240 | - if (! is_string($middleware)) { |
|
| 241 | - continue; |
|
| 242 | - } |
|
| 239 | + foreach ($middlewares as $middleware) { |
|
| 240 | + if (! is_string($middleware)) { |
|
| 241 | + continue; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - [$name] = $this->parseMiddleware($middleware); |
|
| 244 | + [$name] = $this->parseMiddleware($middleware); |
|
| 245 | 245 | |
| 246 | - $instance = $this->app->make($name); |
|
| 246 | + $instance = $this->app->make($name); |
|
| 247 | 247 | |
| 248 | - if (method_exists($instance, 'shutdown')) { |
|
| 249 | - $instance->shutdown($request, $response); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 248 | + if (method_exists($instance, 'shutdown')) { |
|
| 249 | + $instance->shutdown($request, $response); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Gather the route middleware for the given request. |
|
| 256 | - * |
|
| 257 | - * @param \Syscodes\Http\Request $request |
|
| 258 | - * |
|
| 259 | - * @return array |
|
| 260 | - */ |
|
| 261 | - protected function gatherRouteMiddleware($request) |
|
| 262 | - { |
|
| 263 | - if ( ! is_null($route = $request->route())) { |
|
| 264 | - return $this->router->gatherRouteMiddleware($route); |
|
| 265 | - } |
|
| 254 | + /** |
|
| 255 | + * Gather the route middleware for the given request. |
|
| 256 | + * |
|
| 257 | + * @param \Syscodes\Http\Request $request |
|
| 258 | + * |
|
| 259 | + * @return array |
|
| 260 | + */ |
|
| 261 | + protected function gatherRouteMiddleware($request) |
|
| 262 | + { |
|
| 263 | + if ( ! is_null($route = $request->route())) { |
|
| 264 | + return $this->router->gatherRouteMiddleware($route); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - return []; |
|
| 268 | - } |
|
| 267 | + return []; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Parse a middleware string to get the name and parameters. |
|
| 272 | - * |
|
| 273 | - * @param string $middleware |
|
| 274 | - * |
|
| 275 | - * @return array |
|
| 276 | - */ |
|
| 277 | - protected function parseMiddleware($middleware) |
|
| 278 | - { |
|
| 279 | - [$name, $parameters] = array_pad(explode(':', $middleware, 2), 2, []); |
|
| 270 | + /** |
|
| 271 | + * Parse a middleware string to get the name and parameters. |
|
| 272 | + * |
|
| 273 | + * @param string $middleware |
|
| 274 | + * |
|
| 275 | + * @return array |
|
| 276 | + */ |
|
| 277 | + protected function parseMiddleware($middleware) |
|
| 278 | + { |
|
| 279 | + [$name, $parameters] = array_pad(explode(':', $middleware, 2), 2, []); |
|
| 280 | 280 | |
| 281 | - if (is_string($parameters)) { |
|
| 282 | - $parameters = explode(',', $parameters); |
|
| 283 | - } |
|
| 281 | + if (is_string($parameters)) { |
|
| 282 | + $parameters = explode(',', $parameters); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - return [$name, $parameters]; |
|
| 285 | + return [$name, $parameters]; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Report the exception to the exception handler. |
|
| 290 | - * |
|
| 291 | - * @param \Throwable $e |
|
| 292 | - * |
|
| 293 | - * @return void |
|
| 294 | - */ |
|
| 295 | - protected function reportException(Throwable $e) |
|
| 296 | - { |
|
| 297 | - return $this->app[ExceptionHandler::class]->report($e); |
|
| 298 | - } |
|
| 288 | + /** |
|
| 289 | + * Report the exception to the exception handler. |
|
| 290 | + * |
|
| 291 | + * @param \Throwable $e |
|
| 292 | + * |
|
| 293 | + * @return void |
|
| 294 | + */ |
|
| 295 | + protected function reportException(Throwable $e) |
|
| 296 | + { |
|
| 297 | + return $this->app[ExceptionHandler::class]->report($e); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Render the exception to a response. |
|
| 302 | - * |
|
| 303 | - * @param \Syscodes\Http\Request $request |
|
| 304 | - * @param \Throwable $e |
|
| 305 | - * |
|
| 306 | - * @return \Syscodes\Http\Response |
|
| 307 | - */ |
|
| 308 | - protected function renderException($request, Throwable $e) |
|
| 309 | - { |
|
| 310 | - return $this->app[ExceptionHandler::class]->render($request, $e); |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | 300 | \ No newline at end of file |
| 301 | + /** |
|
| 302 | + * Render the exception to a response. |
|
| 303 | + * |
|
| 304 | + * @param \Syscodes\Http\Request $request |
|
| 305 | + * @param \Throwable $e |
|
| 306 | + * |
|
| 307 | + * @return \Syscodes\Http\Response |
|
| 308 | + */ |
|
| 309 | + protected function renderException($request, Throwable $e) |
|
| 310 | + { |
|
| 311 | + return $this->app[ExceptionHandler::class]->render($request, $e); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | 314 | \ No newline at end of file |