@@ -16,37 +16,37 @@ |
||
| 16 | 16 | use WPB\Application; |
| 17 | 17 | |
| 18 | 18 | $app = ( new Application( |
| 19 | - array( |
|
| 20 | - 'paths' => array( |
|
| 21 | - 'root' => WPB_APP_ROOT, |
|
| 22 | - ), |
|
| 23 | - ) |
|
| 19 | + array( |
|
| 20 | + 'paths' => array( |
|
| 21 | + 'root' => WPB_APP_ROOT, |
|
| 22 | + ), |
|
| 23 | + ) |
|
| 24 | 24 | ) ); |
| 25 | 25 | |
| 26 | 26 | $container = $app->get_instance(); |
| 27 | 27 | |
| 28 | 28 | $container->singleton( |
| 29 | - Illuminate\Contracts\Http\Kernel::class, |
|
| 30 | - \WPB\App\Http\Kernel::class |
|
| 29 | + Illuminate\Contracts\Http\Kernel::class, |
|
| 30 | + \WPB\App\Http\Kernel::class |
|
| 31 | 31 | ); |
| 32 | 32 | $container->singleton( |
| 33 | - \Illuminate\Contracts\Debug\ExceptionHandler::class, |
|
| 34 | - \WPB\App\Exceptions\Handler::class |
|
| 33 | + \Illuminate\Contracts\Debug\ExceptionHandler::class, |
|
| 34 | + \WPB\App\Exceptions\Handler::class |
|
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | 37 | if ( \WPB\Support\Facades\Route::exists( \Illuminate\Http\Request::capture() ) ) { |
| 38 | - try { |
|
| 38 | + try { |
|
| 39 | 39 | |
| 40 | - $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
| 40 | + $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
| 41 | 41 | |
| 42 | - $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
| 42 | + $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
| 43 | 43 | |
| 44 | - $response->send(); |
|
| 44 | + $response->send(); |
|
| 45 | 45 | |
| 46 | - } catch ( \Exception $ex ) { |
|
| 47 | - if ( ! \WPB\Support\Facades\Route::current() ) { |
|
| 48 | - return true; |
|
| 49 | - } |
|
| 50 | - throw new \Exception( $ex, 1 ); |
|
| 51 | - } |
|
| 46 | + } catch ( \Exception $ex ) { |
|
| 47 | + if ( ! \WPB\Support\Facades\Route::current() ) { |
|
| 48 | + return true; |
|
| 49 | + } |
|
| 50 | + throw new \Exception( $ex, 1 ); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -9,19 +9,19 @@ discard block |
||
| 9 | 9 | * @subpackage WPB/bootstrap |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -require_once ABSPATH . 'wp-includes/pluggable.php'; |
|
| 13 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 14 | -require_once __DIR__ . '/../src/helpers.php'; |
|
| 12 | +require_once ABSPATH.'wp-includes/pluggable.php'; |
|
| 13 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 14 | +require_once __DIR__.'/../src/helpers.php'; |
|
| 15 | 15 | |
| 16 | 16 | use WPB\Application; |
| 17 | 17 | |
| 18 | -$app = ( new Application( |
|
| 18 | +$app = (new Application( |
|
| 19 | 19 | array( |
| 20 | 20 | 'paths' => array( |
| 21 | 21 | 'root' => WPB_APP_ROOT, |
| 22 | 22 | ), |
| 23 | 23 | ) |
| 24 | -) ); |
|
| 24 | +)); |
|
| 25 | 25 | |
| 26 | 26 | $container = $app->get_instance(); |
| 27 | 27 | |
@@ -34,19 +34,19 @@ discard block |
||
| 34 | 34 | \WPB\App\Exceptions\Handler::class |
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | -if ( \WPB\Support\Facades\Route::exists( \Illuminate\Http\Request::capture() ) ) { |
|
| 37 | +if (\WPB\Support\Facades\Route::exists(\Illuminate\Http\Request::capture())) { |
|
| 38 | 38 | try { |
| 39 | 39 | |
| 40 | - $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
| 40 | + $kernel = $container->make(\Illuminate\Contracts\Http\Kernel::class); |
|
| 41 | 41 | |
| 42 | - $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
| 42 | + $response = $kernel->handle(\Illuminate\Http\Request::capture()); |
|
| 43 | 43 | |
| 44 | 44 | $response->send(); |
| 45 | 45 | |
| 46 | - } catch ( \Exception $ex ) { |
|
| 47 | - if ( ! \WPB\Support\Facades\Route::current() ) { |
|
| 46 | + } catch (\Exception $ex) { |
|
| 47 | + if (!\WPB\Support\Facades\Route::current()) { |
|
| 48 | 48 | return true; |
| 49 | 49 | } |
| 50 | - throw new \Exception( $ex, 1 ); |
|
| 50 | + throw new \Exception($ex, 1); |
|
| 51 | 51 | } |
| 52 | 52 | } |
@@ -31,410 +31,410 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Kernel implements KernelContract { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * The application implementation. |
|
| 36 | - * |
|
| 37 | - * @var \Illuminate\Contracts\Foundation\Application |
|
| 38 | - */ |
|
| 39 | - protected $app; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The router instance. |
|
| 43 | - * |
|
| 44 | - * @var \Illuminate\Routing\Router |
|
| 45 | - */ |
|
| 46 | - protected $router; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * The bootstrap classes for the application. |
|
| 50 | - * |
|
| 51 | - * @var array |
|
| 52 | - */ |
|
| 53 | - protected $bootstrappers = array(); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The application's middleware stack. |
|
| 57 | - * |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - protected $middleware = array(); |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * The application's route middleware groups. |
|
| 64 | - * |
|
| 65 | - * @var array |
|
| 66 | - */ |
|
| 67 | - protected $middleware_groups = array(); |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The application's route middleware. |
|
| 71 | - * |
|
| 72 | - * @var array |
|
| 73 | - */ |
|
| 74 | - protected $route_middleware = array(); |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * The priority-sorted list of middleware. |
|
| 78 | - * |
|
| 79 | - * Forces non-global middleware to always be in the given order. |
|
| 80 | - * |
|
| 81 | - * @var array |
|
| 82 | - */ |
|
| 83 | - protected $middleware_priority = array(); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Create a new HTTP kernel instance. |
|
| 87 | - * |
|
| 88 | - * @param \Illuminate\Contracts\Container\Container $app The app. |
|
| 89 | - * @param \Illuminate\Routing\Router $router The app router. |
|
| 90 | - * |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - public function __construct( Container $app, Router $router ) { |
|
| 94 | - $this->app = $app; |
|
| 95 | - $this->router = $router; |
|
| 96 | - |
|
| 97 | - $this->sync_middleware_to_router(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Handle an incoming HTTP request. |
|
| 102 | - * |
|
| 103 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 104 | - * |
|
| 105 | - * @throws \Exception The throwable exception. |
|
| 106 | - * |
|
| 107 | - * @return \Illuminate\Http\Response |
|
| 108 | - */ |
|
| 109 | - public function handle( $request ) { |
|
| 110 | - try { |
|
| 111 | - $request->enableHttpMethodParameterOverride(); |
|
| 112 | - $response = $this->send_request_through_router( $request ); |
|
| 113 | - } catch ( Throwable $e ) { |
|
| 114 | - $this->report_exception( $e ); |
|
| 115 | - $response = $this->render_exception( $request, $e ); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $this->app['events']->dispatch( |
|
| 119 | - new RequestHandled( $request, $response ) |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - return $response; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Send the given request through the middleware / router. |
|
| 127 | - * |
|
| 128 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 129 | - * |
|
| 130 | - * @return \Illuminate\Http\Response |
|
| 131 | - */ |
|
| 132 | - protected function send_request_through_router( $request ) { |
|
| 133 | - $this->app->instance( 'request', $request ); |
|
| 134 | - |
|
| 135 | - Facade::clearResolvedInstance( 'request' ); |
|
| 136 | - |
|
| 137 | - $this->bootstrap(); |
|
| 138 | - |
|
| 139 | - return ( new Pipeline( $this->app ) ) |
|
| 140 | - ->send( $request ) |
|
| 141 | - ->through( $this->middleware ) |
|
| 142 | - ->then( $this->dispatch_to_router() ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Bootstrap the application for HTTP requests. |
|
| 147 | - * |
|
| 148 | - * @return void |
|
| 149 | - */ |
|
| 150 | - public function bootstrap() {} |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Get the route dispatcher callback. |
|
| 154 | - * |
|
| 155 | - * @return \Closure |
|
| 156 | - */ |
|
| 157 | - protected function dispatch_to_router() { |
|
| 158 | - return function ( $request ) { |
|
| 159 | - $this->app->instance( 'request', $request ); |
|
| 160 | - |
|
| 161 | - return $this->router->dispatch( $request ); |
|
| 162 | - }; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Call the terminate method on any terminable middleware. |
|
| 167 | - * |
|
| 168 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 169 | - * @param \Illuminate\Http\Response $response The app http response. |
|
| 170 | - * |
|
| 171 | - * @return void |
|
| 172 | - */ |
|
| 173 | - public function terminate( $request, $response ) { |
|
| 174 | - $this->terminate_middleware( $request, $response ); |
|
| 175 | - |
|
| 176 | - $this->app->terminate(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Call the terminate method on any terminable middleware. |
|
| 181 | - * |
|
| 182 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 183 | - * @param \Illuminate\Http\Response $response The app http response. |
|
| 184 | - * |
|
| 185 | - * @return void |
|
| 186 | - */ |
|
| 187 | - protected function terminate_middleware( $request, $response ) { |
|
| 188 | - $middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge( |
|
| 189 | - $this->gather_route_middleware( $request ), |
|
| 190 | - $this->middleware |
|
| 191 | - ); |
|
| 192 | - |
|
| 193 | - foreach ( $middlewares as $middleware ) { |
|
| 194 | - if ( ! is_string( $middleware ) ) { |
|
| 195 | - continue; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - list( $name ) = $this->parse_middleware( $middleware ); |
|
| 199 | - |
|
| 200 | - $instance = $this->app->make( $name ); |
|
| 201 | - |
|
| 202 | - if ( method_exists( $instance, 'terminate' ) ) { |
|
| 203 | - $instance->terminate( $request, $response ); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Gather the route middleware for the given request. |
|
| 210 | - * |
|
| 211 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 212 | - * |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - protected function gather_route_middleware( $request ) { |
|
| 216 | - $route = $request->route(); |
|
| 217 | - if ( $route ) { |
|
| 218 | - return $this->router->gatherRouteMiddleware( $route ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - return array(); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Parse a middleware string to get the name and parameters. |
|
| 226 | - * |
|
| 227 | - * @param string $middleware The app middleware. |
|
| 228 | - * |
|
| 229 | - * @return array |
|
| 230 | - */ |
|
| 231 | - protected function parse_middleware( $middleware ) { |
|
| 232 | - |
|
| 233 | - list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() ); |
|
| 234 | - |
|
| 235 | - if ( is_string( $parameters ) ) { |
|
| 236 | - $parameters = explode( ',', $parameters ); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return array( $name, $parameters ); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Determine if the kernel has a given middleware. |
|
| 244 | - * |
|
| 245 | - * @param string $middleware The app middleware. |
|
| 246 | - * |
|
| 247 | - * @return bool |
|
| 248 | - */ |
|
| 249 | - public function has_middleware( $middleware ) { |
|
| 250 | - return in_array( $middleware, $this->middleware ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Add a new middleware to beginning of the stack if it does not already exist. |
|
| 255 | - * |
|
| 256 | - * @param string $middleware The app middleware. |
|
| 257 | - * |
|
| 258 | - * @return $this |
|
| 259 | - */ |
|
| 260 | - public function prepend_middleware( $middleware ) { |
|
| 261 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 262 | - array_unshift( $this->middleware, $middleware ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - return $this; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Add a new middleware to end of the stack if it does not already exist. |
|
| 270 | - * |
|
| 271 | - * @param string $middleware The app middleware. |
|
| 272 | - * |
|
| 273 | - * @return $this |
|
| 274 | - */ |
|
| 275 | - public function push_middleware( $middleware ) { |
|
| 276 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 277 | - $this->middleware[] = $middleware; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $this; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Prepend the given middleware to the given middleware group. |
|
| 285 | - * |
|
| 286 | - * @param string $group The app group. |
|
| 287 | - * @param string $middleware The app middleware. |
|
| 288 | - * |
|
| 289 | - * @throws \InvalidArgumentException The invalid argument exception. |
|
| 290 | - * |
|
| 291 | - * @return $this |
|
| 292 | - */ |
|
| 293 | - public function prepend_middleware_to_group( $group, $middleware ) { |
|
| 294 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 295 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 299 | - array_unshift( $this->middleware_groups[ $group ], $middleware ); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $this->sync_middleware_to_router(); |
|
| 303 | - |
|
| 304 | - return $this; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Append the given middleware to the given middleware group. |
|
| 309 | - * |
|
| 310 | - * @param string $group The app group. |
|
| 311 | - * @param string $middleware The app middleware. |
|
| 312 | - * |
|
| 313 | - * @throws \InvalidArgumentException The invalid argument exception. |
|
| 314 | - * |
|
| 315 | - * @return $this |
|
| 316 | - */ |
|
| 317 | - public function append_middleware_to_group( $group, $middleware ) { |
|
| 318 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 319 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 323 | - $this->middleware_groups[ $group ][] = $middleware; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - $this->sync_middleware_to_router(); |
|
| 327 | - |
|
| 328 | - return $this; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Prepend the given middleware to the middleware priority list. |
|
| 333 | - * |
|
| 334 | - * @param string $middleware The app middleware. |
|
| 335 | - * |
|
| 336 | - * @return $this |
|
| 337 | - */ |
|
| 338 | - public function prepend_to_middleware_priority( $middleware ) { |
|
| 339 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 340 | - array_unshift( $this->middleware_priority, $middleware ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - $this->sync_middleware_to_router(); |
|
| 344 | - |
|
| 345 | - return $this; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Append the given middleware to the middleware priority list. |
|
| 350 | - * |
|
| 351 | - * @param string $middleware The app middleware. |
|
| 352 | - * |
|
| 353 | - * @return $this |
|
| 354 | - */ |
|
| 355 | - public function append_to_middleware_priority( $middleware ) { |
|
| 356 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 357 | - $this->middleware_priority[] = $middleware; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $this->sync_middleware_to_router(); |
|
| 361 | - |
|
| 362 | - return $this; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Sync the current state of the middleware to the router. |
|
| 367 | - * |
|
| 368 | - * @return void |
|
| 369 | - */ |
|
| 370 | - protected function sync_middleware_to_router() { |
|
| 371 | - $this->router->middlewarePriority = $this->middleware_priority; |
|
| 372 | - |
|
| 373 | - foreach ( $this->middleware_groups as $key => $middleware ) { |
|
| 374 | - $this->router->middlewareGroup( $key, $middleware ); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - foreach ( $this->route_middleware as $key => $middleware ) { |
|
| 378 | - $this->router->aliasMiddleware( $key, $middleware ); |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Get the bootstrap classes for the application. |
|
| 384 | - * |
|
| 385 | - * @return array |
|
| 386 | - */ |
|
| 387 | - protected function bootstrappers() { |
|
| 388 | - return $this->bootstrappers; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Report the exception to the exception handler. |
|
| 393 | - * |
|
| 394 | - * @param \Throwable $e The throwable exception. |
|
| 395 | - * |
|
| 396 | - * @return void |
|
| 397 | - */ |
|
| 398 | - protected function report_exception( Throwable $e ) { |
|
| 399 | - $this->app[ ExceptionHandler::class ]->report( $e ); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Render the exception to a response. |
|
| 404 | - * |
|
| 405 | - * @param \Illuminate\Http\Request $request The app http request. |
|
| 406 | - * @param \Throwable $e The throwable exception. |
|
| 407 | - * |
|
| 408 | - * @return \Symfony\Component\HttpFoundation\Response |
|
| 409 | - */ |
|
| 410 | - protected function render_exception( $request, Throwable $e ) { |
|
| 411 | - return $this->app[ ExceptionHandler::class ]->render( $request, $e ); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Get the application's route middleware groups. |
|
| 416 | - * |
|
| 417 | - * @return array |
|
| 418 | - */ |
|
| 419 | - public function get_middleware_groups() { |
|
| 420 | - return $this->middleware_groups; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Get the application's route middleware. |
|
| 425 | - * |
|
| 426 | - * @return array |
|
| 427 | - */ |
|
| 428 | - public function get_route_middleware() { |
|
| 429 | - return $this->route_middleware; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Get the Laravel application instance. |
|
| 434 | - * |
|
| 435 | - * @return \Illuminate\Contracts\Foundation\Application |
|
| 436 | - */ |
|
| 437 | - public function get_application() { |
|
| 438 | - return $this->app; |
|
| 439 | - } |
|
| 34 | + /** |
|
| 35 | + * The application implementation. |
|
| 36 | + * |
|
| 37 | + * @var \Illuminate\Contracts\Foundation\Application |
|
| 38 | + */ |
|
| 39 | + protected $app; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The router instance. |
|
| 43 | + * |
|
| 44 | + * @var \Illuminate\Routing\Router |
|
| 45 | + */ |
|
| 46 | + protected $router; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * The bootstrap classes for the application. |
|
| 50 | + * |
|
| 51 | + * @var array |
|
| 52 | + */ |
|
| 53 | + protected $bootstrappers = array(); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The application's middleware stack. |
|
| 57 | + * |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + protected $middleware = array(); |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * The application's route middleware groups. |
|
| 64 | + * |
|
| 65 | + * @var array |
|
| 66 | + */ |
|
| 67 | + protected $middleware_groups = array(); |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The application's route middleware. |
|
| 71 | + * |
|
| 72 | + * @var array |
|
| 73 | + */ |
|
| 74 | + protected $route_middleware = array(); |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * The priority-sorted list of middleware. |
|
| 78 | + * |
|
| 79 | + * Forces non-global middleware to always be in the given order. |
|
| 80 | + * |
|
| 81 | + * @var array |
|
| 82 | + */ |
|
| 83 | + protected $middleware_priority = array(); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Create a new HTTP kernel instance. |
|
| 87 | + * |
|
| 88 | + * @param \Illuminate\Contracts\Container\Container $app The app. |
|
| 89 | + * @param \Illuminate\Routing\Router $router The app router. |
|
| 90 | + * |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + public function __construct( Container $app, Router $router ) { |
|
| 94 | + $this->app = $app; |
|
| 95 | + $this->router = $router; |
|
| 96 | + |
|
| 97 | + $this->sync_middleware_to_router(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Handle an incoming HTTP request. |
|
| 102 | + * |
|
| 103 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 104 | + * |
|
| 105 | + * @throws \Exception The throwable exception. |
|
| 106 | + * |
|
| 107 | + * @return \Illuminate\Http\Response |
|
| 108 | + */ |
|
| 109 | + public function handle( $request ) { |
|
| 110 | + try { |
|
| 111 | + $request->enableHttpMethodParameterOverride(); |
|
| 112 | + $response = $this->send_request_through_router( $request ); |
|
| 113 | + } catch ( Throwable $e ) { |
|
| 114 | + $this->report_exception( $e ); |
|
| 115 | + $response = $this->render_exception( $request, $e ); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $this->app['events']->dispatch( |
|
| 119 | + new RequestHandled( $request, $response ) |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + return $response; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Send the given request through the middleware / router. |
|
| 127 | + * |
|
| 128 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 129 | + * |
|
| 130 | + * @return \Illuminate\Http\Response |
|
| 131 | + */ |
|
| 132 | + protected function send_request_through_router( $request ) { |
|
| 133 | + $this->app->instance( 'request', $request ); |
|
| 134 | + |
|
| 135 | + Facade::clearResolvedInstance( 'request' ); |
|
| 136 | + |
|
| 137 | + $this->bootstrap(); |
|
| 138 | + |
|
| 139 | + return ( new Pipeline( $this->app ) ) |
|
| 140 | + ->send( $request ) |
|
| 141 | + ->through( $this->middleware ) |
|
| 142 | + ->then( $this->dispatch_to_router() ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Bootstrap the application for HTTP requests. |
|
| 147 | + * |
|
| 148 | + * @return void |
|
| 149 | + */ |
|
| 150 | + public function bootstrap() {} |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Get the route dispatcher callback. |
|
| 154 | + * |
|
| 155 | + * @return \Closure |
|
| 156 | + */ |
|
| 157 | + protected function dispatch_to_router() { |
|
| 158 | + return function ( $request ) { |
|
| 159 | + $this->app->instance( 'request', $request ); |
|
| 160 | + |
|
| 161 | + return $this->router->dispatch( $request ); |
|
| 162 | + }; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Call the terminate method on any terminable middleware. |
|
| 167 | + * |
|
| 168 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 169 | + * @param \Illuminate\Http\Response $response The app http response. |
|
| 170 | + * |
|
| 171 | + * @return void |
|
| 172 | + */ |
|
| 173 | + public function terminate( $request, $response ) { |
|
| 174 | + $this->terminate_middleware( $request, $response ); |
|
| 175 | + |
|
| 176 | + $this->app->terminate(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Call the terminate method on any terminable middleware. |
|
| 181 | + * |
|
| 182 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 183 | + * @param \Illuminate\Http\Response $response The app http response. |
|
| 184 | + * |
|
| 185 | + * @return void |
|
| 186 | + */ |
|
| 187 | + protected function terminate_middleware( $request, $response ) { |
|
| 188 | + $middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge( |
|
| 189 | + $this->gather_route_middleware( $request ), |
|
| 190 | + $this->middleware |
|
| 191 | + ); |
|
| 192 | + |
|
| 193 | + foreach ( $middlewares as $middleware ) { |
|
| 194 | + if ( ! is_string( $middleware ) ) { |
|
| 195 | + continue; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + list( $name ) = $this->parse_middleware( $middleware ); |
|
| 199 | + |
|
| 200 | + $instance = $this->app->make( $name ); |
|
| 201 | + |
|
| 202 | + if ( method_exists( $instance, 'terminate' ) ) { |
|
| 203 | + $instance->terminate( $request, $response ); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Gather the route middleware for the given request. |
|
| 210 | + * |
|
| 211 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 212 | + * |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + protected function gather_route_middleware( $request ) { |
|
| 216 | + $route = $request->route(); |
|
| 217 | + if ( $route ) { |
|
| 218 | + return $this->router->gatherRouteMiddleware( $route ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + return array(); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Parse a middleware string to get the name and parameters. |
|
| 226 | + * |
|
| 227 | + * @param string $middleware The app middleware. |
|
| 228 | + * |
|
| 229 | + * @return array |
|
| 230 | + */ |
|
| 231 | + protected function parse_middleware( $middleware ) { |
|
| 232 | + |
|
| 233 | + list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() ); |
|
| 234 | + |
|
| 235 | + if ( is_string( $parameters ) ) { |
|
| 236 | + $parameters = explode( ',', $parameters ); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return array( $name, $parameters ); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Determine if the kernel has a given middleware. |
|
| 244 | + * |
|
| 245 | + * @param string $middleware The app middleware. |
|
| 246 | + * |
|
| 247 | + * @return bool |
|
| 248 | + */ |
|
| 249 | + public function has_middleware( $middleware ) { |
|
| 250 | + return in_array( $middleware, $this->middleware ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Add a new middleware to beginning of the stack if it does not already exist. |
|
| 255 | + * |
|
| 256 | + * @param string $middleware The app middleware. |
|
| 257 | + * |
|
| 258 | + * @return $this |
|
| 259 | + */ |
|
| 260 | + public function prepend_middleware( $middleware ) { |
|
| 261 | + if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 262 | + array_unshift( $this->middleware, $middleware ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + return $this; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Add a new middleware to end of the stack if it does not already exist. |
|
| 270 | + * |
|
| 271 | + * @param string $middleware The app middleware. |
|
| 272 | + * |
|
| 273 | + * @return $this |
|
| 274 | + */ |
|
| 275 | + public function push_middleware( $middleware ) { |
|
| 276 | + if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 277 | + $this->middleware[] = $middleware; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $this; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Prepend the given middleware to the given middleware group. |
|
| 285 | + * |
|
| 286 | + * @param string $group The app group. |
|
| 287 | + * @param string $middleware The app middleware. |
|
| 288 | + * |
|
| 289 | + * @throws \InvalidArgumentException The invalid argument exception. |
|
| 290 | + * |
|
| 291 | + * @return $this |
|
| 292 | + */ |
|
| 293 | + public function prepend_middleware_to_group( $group, $middleware ) { |
|
| 294 | + if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 295 | + throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 299 | + array_unshift( $this->middleware_groups[ $group ], $middleware ); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $this->sync_middleware_to_router(); |
|
| 303 | + |
|
| 304 | + return $this; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Append the given middleware to the given middleware group. |
|
| 309 | + * |
|
| 310 | + * @param string $group The app group. |
|
| 311 | + * @param string $middleware The app middleware. |
|
| 312 | + * |
|
| 313 | + * @throws \InvalidArgumentException The invalid argument exception. |
|
| 314 | + * |
|
| 315 | + * @return $this |
|
| 316 | + */ |
|
| 317 | + public function append_middleware_to_group( $group, $middleware ) { |
|
| 318 | + if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 319 | + throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 323 | + $this->middleware_groups[ $group ][] = $middleware; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + $this->sync_middleware_to_router(); |
|
| 327 | + |
|
| 328 | + return $this; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Prepend the given middleware to the middleware priority list. |
|
| 333 | + * |
|
| 334 | + * @param string $middleware The app middleware. |
|
| 335 | + * |
|
| 336 | + * @return $this |
|
| 337 | + */ |
|
| 338 | + public function prepend_to_middleware_priority( $middleware ) { |
|
| 339 | + if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 340 | + array_unshift( $this->middleware_priority, $middleware ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + $this->sync_middleware_to_router(); |
|
| 344 | + |
|
| 345 | + return $this; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Append the given middleware to the middleware priority list. |
|
| 350 | + * |
|
| 351 | + * @param string $middleware The app middleware. |
|
| 352 | + * |
|
| 353 | + * @return $this |
|
| 354 | + */ |
|
| 355 | + public function append_to_middleware_priority( $middleware ) { |
|
| 356 | + if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 357 | + $this->middleware_priority[] = $middleware; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $this->sync_middleware_to_router(); |
|
| 361 | + |
|
| 362 | + return $this; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Sync the current state of the middleware to the router. |
|
| 367 | + * |
|
| 368 | + * @return void |
|
| 369 | + */ |
|
| 370 | + protected function sync_middleware_to_router() { |
|
| 371 | + $this->router->middlewarePriority = $this->middleware_priority; |
|
| 372 | + |
|
| 373 | + foreach ( $this->middleware_groups as $key => $middleware ) { |
|
| 374 | + $this->router->middlewareGroup( $key, $middleware ); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + foreach ( $this->route_middleware as $key => $middleware ) { |
|
| 378 | + $this->router->aliasMiddleware( $key, $middleware ); |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Get the bootstrap classes for the application. |
|
| 384 | + * |
|
| 385 | + * @return array |
|
| 386 | + */ |
|
| 387 | + protected function bootstrappers() { |
|
| 388 | + return $this->bootstrappers; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Report the exception to the exception handler. |
|
| 393 | + * |
|
| 394 | + * @param \Throwable $e The throwable exception. |
|
| 395 | + * |
|
| 396 | + * @return void |
|
| 397 | + */ |
|
| 398 | + protected function report_exception( Throwable $e ) { |
|
| 399 | + $this->app[ ExceptionHandler::class ]->report( $e ); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Render the exception to a response. |
|
| 404 | + * |
|
| 405 | + * @param \Illuminate\Http\Request $request The app http request. |
|
| 406 | + * @param \Throwable $e The throwable exception. |
|
| 407 | + * |
|
| 408 | + * @return \Symfony\Component\HttpFoundation\Response |
|
| 409 | + */ |
|
| 410 | + protected function render_exception( $request, Throwable $e ) { |
|
| 411 | + return $this->app[ ExceptionHandler::class ]->render( $request, $e ); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Get the application's route middleware groups. |
|
| 416 | + * |
|
| 417 | + * @return array |
|
| 418 | + */ |
|
| 419 | + public function get_middleware_groups() { |
|
| 420 | + return $this->middleware_groups; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Get the application's route middleware. |
|
| 425 | + * |
|
| 426 | + * @return array |
|
| 427 | + */ |
|
| 428 | + public function get_route_middleware() { |
|
| 429 | + return $this->route_middleware; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Get the Laravel application instance. |
|
| 434 | + * |
|
| 435 | + * @return \Illuminate\Contracts\Foundation\Application |
|
| 436 | + */ |
|
| 437 | + public function get_application() { |
|
| 438 | + return $this->app; |
|
| 439 | + } |
|
| 440 | 440 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | - public function __construct( Container $app, Router $router ) { |
|
| 93 | + public function __construct(Container $app, Router $router) { |
|
| 94 | 94 | $this->app = $app; |
| 95 | 95 | $this->router = $router; |
| 96 | 96 | |
@@ -106,17 +106,17 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @return \Illuminate\Http\Response |
| 108 | 108 | */ |
| 109 | - public function handle( $request ) { |
|
| 109 | + public function handle($request) { |
|
| 110 | 110 | try { |
| 111 | 111 | $request->enableHttpMethodParameterOverride(); |
| 112 | - $response = $this->send_request_through_router( $request ); |
|
| 113 | - } catch ( Throwable $e ) { |
|
| 114 | - $this->report_exception( $e ); |
|
| 115 | - $response = $this->render_exception( $request, $e ); |
|
| 112 | + $response = $this->send_request_through_router($request); |
|
| 113 | + } catch (Throwable $e) { |
|
| 114 | + $this->report_exception($e); |
|
| 115 | + $response = $this->render_exception($request, $e); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | $this->app['events']->dispatch( |
| 119 | - new RequestHandled( $request, $response ) |
|
| 119 | + new RequestHandled($request, $response) |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | return $response; |
@@ -129,17 +129,17 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return \Illuminate\Http\Response |
| 131 | 131 | */ |
| 132 | - protected function send_request_through_router( $request ) { |
|
| 133 | - $this->app->instance( 'request', $request ); |
|
| 132 | + protected function send_request_through_router($request) { |
|
| 133 | + $this->app->instance('request', $request); |
|
| 134 | 134 | |
| 135 | - Facade::clearResolvedInstance( 'request' ); |
|
| 135 | + Facade::clearResolvedInstance('request'); |
|
| 136 | 136 | |
| 137 | 137 | $this->bootstrap(); |
| 138 | 138 | |
| 139 | - return ( new Pipeline( $this->app ) ) |
|
| 140 | - ->send( $request ) |
|
| 141 | - ->through( $this->middleware ) |
|
| 142 | - ->then( $this->dispatch_to_router() ); |
|
| 139 | + return (new Pipeline($this->app)) |
|
| 140 | + ->send($request) |
|
| 141 | + ->through($this->middleware) |
|
| 142 | + ->then($this->dispatch_to_router()); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -155,10 +155,10 @@ discard block |
||
| 155 | 155 | * @return \Closure |
| 156 | 156 | */ |
| 157 | 157 | protected function dispatch_to_router() { |
| 158 | - return function ( $request ) { |
|
| 159 | - $this->app->instance( 'request', $request ); |
|
| 158 | + return function($request) { |
|
| 159 | + $this->app->instance('request', $request); |
|
| 160 | 160 | |
| 161 | - return $this->router->dispatch( $request ); |
|
| 161 | + return $this->router->dispatch($request); |
|
| 162 | 162 | }; |
| 163 | 163 | } |
| 164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @return void |
| 172 | 172 | */ |
| 173 | - public function terminate( $request, $response ) { |
|
| 174 | - $this->terminate_middleware( $request, $response ); |
|
| 173 | + public function terminate($request, $response) { |
|
| 174 | + $this->terminate_middleware($request, $response); |
|
| 175 | 175 | |
| 176 | 176 | $this->app->terminate(); |
| 177 | 177 | } |
@@ -184,23 +184,23 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return void |
| 186 | 186 | */ |
| 187 | - protected function terminate_middleware( $request, $response ) { |
|
| 187 | + protected function terminate_middleware($request, $response) { |
|
| 188 | 188 | $middlewares = $this->app->shouldSkipMiddleware() ? array() : array_merge( |
| 189 | - $this->gather_route_middleware( $request ), |
|
| 189 | + $this->gather_route_middleware($request), |
|
| 190 | 190 | $this->middleware |
| 191 | 191 | ); |
| 192 | 192 | |
| 193 | - foreach ( $middlewares as $middleware ) { |
|
| 194 | - if ( ! is_string( $middleware ) ) { |
|
| 193 | + foreach ($middlewares as $middleware) { |
|
| 194 | + if (!is_string($middleware)) { |
|
| 195 | 195 | continue; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - list( $name ) = $this->parse_middleware( $middleware ); |
|
| 198 | + list($name) = $this->parse_middleware($middleware); |
|
| 199 | 199 | |
| 200 | - $instance = $this->app->make( $name ); |
|
| 200 | + $instance = $this->app->make($name); |
|
| 201 | 201 | |
| 202 | - if ( method_exists( $instance, 'terminate' ) ) { |
|
| 203 | - $instance->terminate( $request, $response ); |
|
| 202 | + if (method_exists($instance, 'terminate')) { |
|
| 203 | + $instance->terminate($request, $response); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -212,10 +212,10 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | - protected function gather_route_middleware( $request ) { |
|
| 215 | + protected function gather_route_middleware($request) { |
|
| 216 | 216 | $route = $request->route(); |
| 217 | - if ( $route ) { |
|
| 218 | - return $this->router->gatherRouteMiddleware( $route ); |
|
| 217 | + if ($route) { |
|
| 218 | + return $this->router->gatherRouteMiddleware($route); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | return array(); |
@@ -228,15 +228,15 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @return array |
| 230 | 230 | */ |
| 231 | - protected function parse_middleware( $middleware ) { |
|
| 231 | + protected function parse_middleware($middleware) { |
|
| 232 | 232 | |
| 233 | - list( $name, $parameters ) = array_pad( explode( ':', $middleware, 2 ), 2, array() ); |
|
| 233 | + list($name, $parameters) = array_pad(explode(':', $middleware, 2), 2, array()); |
|
| 234 | 234 | |
| 235 | - if ( is_string( $parameters ) ) { |
|
| 236 | - $parameters = explode( ',', $parameters ); |
|
| 235 | + if (is_string($parameters)) { |
|
| 236 | + $parameters = explode(',', $parameters); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - return array( $name, $parameters ); |
|
| 239 | + return array($name, $parameters); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | * |
| 247 | 247 | * @return bool |
| 248 | 248 | */ |
| 249 | - public function has_middleware( $middleware ) { |
|
| 250 | - return in_array( $middleware, $this->middleware ); |
|
| 249 | + public function has_middleware($middleware) { |
|
| 250 | + return in_array($middleware, $this->middleware); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @return $this |
| 259 | 259 | */ |
| 260 | - public function prepend_middleware( $middleware ) { |
|
| 261 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 262 | - array_unshift( $this->middleware, $middleware ); |
|
| 260 | + public function prepend_middleware($middleware) { |
|
| 261 | + if (array_search($middleware, $this->middleware) === false) { |
|
| 262 | + array_unshift($this->middleware, $middleware); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | return $this; |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return $this |
| 274 | 274 | */ |
| 275 | - public function push_middleware( $middleware ) { |
|
| 276 | - if ( array_search( $middleware, $this->middleware ) === false ) { |
|
| 275 | + public function push_middleware($middleware) { |
|
| 276 | + if (array_search($middleware, $this->middleware) === false) { |
|
| 277 | 277 | $this->middleware[] = $middleware; |
| 278 | 278 | } |
| 279 | 279 | |
@@ -290,13 +290,13 @@ discard block |
||
| 290 | 290 | * |
| 291 | 291 | * @return $this |
| 292 | 292 | */ |
| 293 | - public function prepend_middleware_to_group( $group, $middleware ) { |
|
| 294 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 295 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 293 | + public function prepend_middleware_to_group($group, $middleware) { |
|
| 294 | + if (!isset($this->middleware_groups[$group])) { |
|
| 295 | + throw new InvalidArgumentException("The [{$group}] middleware group has not been defined."); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 299 | - array_unshift( $this->middleware_groups[ $group ], $middleware ); |
|
| 298 | + if (array_search($middleware, $this->middleware_groups[$group]) === false) { |
|
| 299 | + array_unshift($this->middleware_groups[$group], $middleware); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $this->sync_middleware_to_router(); |
@@ -314,13 +314,13 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @return $this |
| 316 | 316 | */ |
| 317 | - public function append_middleware_to_group( $group, $middleware ) { |
|
| 318 | - if ( ! isset( $this->middleware_groups[ $group ] ) ) { |
|
| 319 | - throw new InvalidArgumentException( "The [{$group}] middleware group has not been defined." ); |
|
| 317 | + public function append_middleware_to_group($group, $middleware) { |
|
| 318 | + if (!isset($this->middleware_groups[$group])) { |
|
| 319 | + throw new InvalidArgumentException("The [{$group}] middleware group has not been defined."); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( array_search( $middleware, $this->middleware_groups[ $group ] ) === false ) { |
|
| 323 | - $this->middleware_groups[ $group ][] = $middleware; |
|
| 322 | + if (array_search($middleware, $this->middleware_groups[$group]) === false) { |
|
| 323 | + $this->middleware_groups[$group][] = $middleware; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | $this->sync_middleware_to_router(); |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | * |
| 336 | 336 | * @return $this |
| 337 | 337 | */ |
| 338 | - public function prepend_to_middleware_priority( $middleware ) { |
|
| 339 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 340 | - array_unshift( $this->middleware_priority, $middleware ); |
|
| 338 | + public function prepend_to_middleware_priority($middleware) { |
|
| 339 | + if (!in_array($middleware, $this->middleware_priority)) { |
|
| 340 | + array_unshift($this->middleware_priority, $middleware); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $this->sync_middleware_to_router(); |
@@ -352,8 +352,8 @@ discard block |
||
| 352 | 352 | * |
| 353 | 353 | * @return $this |
| 354 | 354 | */ |
| 355 | - public function append_to_middleware_priority( $middleware ) { |
|
| 356 | - if ( ! in_array( $middleware, $this->middleware_priority ) ) { |
|
| 355 | + public function append_to_middleware_priority($middleware) { |
|
| 356 | + if (!in_array($middleware, $this->middleware_priority)) { |
|
| 357 | 357 | $this->middleware_priority[] = $middleware; |
| 358 | 358 | } |
| 359 | 359 | |
@@ -370,12 +370,12 @@ discard block |
||
| 370 | 370 | protected function sync_middleware_to_router() { |
| 371 | 371 | $this->router->middlewarePriority = $this->middleware_priority; |
| 372 | 372 | |
| 373 | - foreach ( $this->middleware_groups as $key => $middleware ) { |
|
| 374 | - $this->router->middlewareGroup( $key, $middleware ); |
|
| 373 | + foreach ($this->middleware_groups as $key => $middleware) { |
|
| 374 | + $this->router->middlewareGroup($key, $middleware); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - foreach ( $this->route_middleware as $key => $middleware ) { |
|
| 378 | - $this->router->aliasMiddleware( $key, $middleware ); |
|
| 377 | + foreach ($this->route_middleware as $key => $middleware) { |
|
| 378 | + $this->router->aliasMiddleware($key, $middleware); |
|
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | 381 | |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * |
| 396 | 396 | * @return void |
| 397 | 397 | */ |
| 398 | - protected function report_exception( Throwable $e ) { |
|
| 399 | - $this->app[ ExceptionHandler::class ]->report( $e ); |
|
| 398 | + protected function report_exception(Throwable $e) { |
|
| 399 | + $this->app[ExceptionHandler::class]->report($e); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | * |
| 408 | 408 | * @return \Symfony\Component\HttpFoundation\Response |
| 409 | 409 | */ |
| 410 | - protected function render_exception( $request, Throwable $e ) { |
|
| 411 | - return $this->app[ ExceptionHandler::class ]->render( $request, $e ); |
|
| 410 | + protected function render_exception($request, Throwable $e) { |
|
| 411 | + return $this->app[ExceptionHandler::class]->render($request, $e); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |