Kernel
class Kernel implements Kernel
Traits
Constants
| protected REQUEST_STARTED_AT_CONTEXT_KEY |
Context key for the current request's start time. Stored per-coroutine — a singleton Kernel handles concurrent requests and an instance property would be overwritten by whichever coroutine called handle() most recently. |
Properties
| protected Application | $app | The application implementation. |
|
| protected Router | $router | The router instance. |
|
| protected string[] | $bootstrappers | The bootstrap classes for the application. |
|
| protected array<int, class-string|string> | $middleware | The application's middleware stack. |
|
| protected array<string, array<int, class-string|string>> | $middlewareGroups | The application's route middleware groups. |
|
| protected array<string, class-string|string> | $middlewareAliases | The application's middleware aliases. |
|
| protected array<int, array{threshold: float|int, handler: callable}> | $requestLifecycleDurationHandlers | All of the registered request duration handlers. |
|
| protected string[] | $middlewarePriority | The priority-sorted list of middleware. |
Methods
Get the number of seconds until the given DateTime.
Get the "available at" UNIX timestamp.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Bootstrap the application for HTTP requests.
Get the route dispatcher callback.
Call the terminate method on any terminable middleware.
Register a callback to be invoked when the request lifecycle duration exceeds a given amount of time.
Get when the kernel started handling the current request.
Parse a middleware string to get the name and parameters.
Determine if the kernel has a given middleware.
Add a new middleware to the beginning of the stack if it does not already exist.
Add a new middleware to end of the stack if it does not already exist.
Prepend the given middleware to the given middleware group.
Append the given middleware to the given middleware group.
Prepend the given middleware to the middleware priority list.
Append the given middleware to the middleware priority list.
Add the given middleware to the middleware priority list before other middleware.
Add the given middleware to the middleware priority list after other middleware.
Add the given middleware to the middleware priority list relative to other middleware.
Sync the current state of the middleware to the router.
Get the priority-sorted list of middleware.
Get the bootstrap classes for the application.
Get the application's global middleware.
Set the application's global middleware.
Get the application's route middleware groups.
Set the application's middleware groups.
Get the application's route middleware aliases.
Set the application's route middleware aliases.
Set the application's middleware priority.
Get the application instance.
Details
in
InteractsWithTime at line 17
protected int
secondsUntil(DateInterval|DateTimeInterface|int $delay)
Get the number of seconds until the given DateTime.
in
InteractsWithTime at line 29
protected int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)
Get the "available at" UNIX timestamp.
in
InteractsWithTime at line 41
protected DateTimeInterface|int
parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)
If the given value is an interval, convert it to a DateTime instance.
in
InteractsWithTime at line 57
protected int
currentTime()
Get the current system time as a UNIX timestamp.
in
InteractsWithTime at line 65
protected string
runTimeForHumans(float $startTime, float|null $endTime = null)
Given a start time, format the total run time for human readability.
at line 118
__construct(Application $app, Router $router)
Create a new HTTP kernel instance.
at line 129
Response
handle(Request $request)
Handle an incoming HTTP request.
at line 156
protected Response
sendRequestThroughRouter(Request $request)
Send the given request through the middleware / router.
at line 174
void
bootstrap()
Bootstrap the application for HTTP requests.
at line 189
protected Closure
dispatchToRouter()
Get the route dispatcher callback.
Uses RequestContext::set() instead of Laravel's $this->app->instance('request', $request) because instance() writes to process-global $instances which would race across coroutines. The HttpServiceProvider's bind('request', fn () => RequestContext::get()) ensures all resolution paths return the coroutine-local request.
at line 201
void
terminate(Request $request, Response $response)
Perform any final actions for the request lifecycle.
at line 266
protected void
terminateMiddleware(Request $request, Response $response)
Call the terminate method on any terminable middleware.
at line 307
void
whenRequestLifecycleIsLongerThan(DateTimeInterface|CarbonInterval|float|int $threshold, callable $handler)
Register a callback to be invoked when the request lifecycle duration exceeds a given amount of time.
at line 326
CarbonImmutable|null
requestStartedAt()
Get when the kernel started handling the current request.
at line 334
protected array
gatherRouteMiddleware(Request $request)
Gather the route middleware for the given request.
at line 346
protected array
parseMiddleware(string $middleware)
Parse a middleware string to get the name and parameters.
at line 360
bool
hasMiddleware(string $middleware)
Determine if the kernel has a given middleware.
at line 374
Kernel
prependMiddleware(string $middleware)
Add a new middleware to the beginning of the stack if it does not already exist.
Boot-only. Middleware persists in the singleton Kernel's global stack for the worker lifetime and runs on every subsequent request across all coroutines.
at line 392
Kernel
pushMiddleware(string $middleware)
Add a new middleware to end of the stack if it does not already exist.
Boot-only. Middleware persists in the singleton Kernel's global stack for the worker lifetime and runs on every subsequent request across all coroutines.
at line 411
Kernel
prependMiddlewareToGroup(string $group, string $middleware)
Prepend the given middleware to the given middleware group.
Boot-only. The middleware group persists in the singleton Kernel for the worker lifetime and runs on every subsequent request matching the group.
at line 436
Kernel
appendMiddlewareToGroup(string $group, string $middleware)
Append the given middleware to the given middleware group.
Boot-only. The middleware group persists in the singleton Kernel for the worker lifetime and runs on every subsequent request matching the group.
at line 460
Kernel
prependToMiddlewarePriority(string $middleware)
Prepend the given middleware to the middleware priority list.
Boot-only. The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.
at line 480
Kernel
appendToMiddlewarePriority(string $middleware)
Append the given middleware to the middleware priority list.
Boot-only. The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.
at line 497
Kernel
addToMiddlewarePriorityBefore(string|array $before, string $middleware)
Add the given middleware to the middleware priority list before other middleware.
at line 508
Kernel
addToMiddlewarePriorityAfter(string|array $after, string $middleware)
Add the given middleware to the middleware priority list after other middleware.
at line 519
protected Kernel
addToMiddlewarePriorityRelative(string|array $existing, string $middleware, bool $after = true)
Add the given middleware to the middleware priority list relative to other middleware.
at line 553
protected void
syncMiddlewareToRouter()
Sync the current state of the middleware to the router.
at line 569
array
getMiddlewarePriority()
Get the priority-sorted list of middleware.
at line 579
protected array
bootstrappers()
Get the bootstrap classes for the application.
at line 587
protected void
reportException(Throwable $e)
Report the exception to the exception handler.
at line 595
protected Response
renderException(Request $request, Throwable $e)
Render the exception to a response.
at line 603
array
getGlobalMiddleware()
Get the application's global middleware.
at line 613
Kernel
setGlobalMiddleware(array $middleware)
Set the application's global middleware.
at line 625
array
getMiddlewareGroups()
Get the application's route middleware groups.
at line 635
Kernel
setMiddlewareGroups(array $groups)
Set the application's middleware groups.
at line 647
array
getMiddlewareAliases()
Get the application's route middleware aliases.
at line 657
Kernel
setMiddlewareAliases(array $aliases)
Set the application's route middleware aliases.
at line 671
Kernel
setMiddlewarePriority(array $priority)
Set the application's middleware priority.
at line 683
Application
getApplication()
Get the application instance.
at line 697
Kernel
setApplication(Application $app)
Set the application instance.
Tests only. Swaps the singleton Kernel's application reference; per-request use races across coroutines and breaks every concurrent request the worker is handling.