Kernel
class Kernel extends Kernel
Minimal HTTP Kernel for testbench.
Bootstrappers are empty because testbench handles application bootstrapping separately via its own setUp flow.
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. |
from Kernel |
| protected Router | $router | The router instance. |
from Kernel |
| protected string[] | $bootstrappers | The bootstrap classes for the application. |
from Kernel |
| protected array<int, class-string|string> | $middleware | The application's middleware stack. |
from Kernel |
| protected array<string, array<int, class-string|string>> | $middlewareGroups | The application's route middleware groups. |
from Kernel |
| protected array<string, class-string|string> | $middlewareAliases | The application's middleware aliases. |
from Kernel |
| protected array<int, array{threshold: float|int, handler: callable}> | $requestLifecycleDurationHandlers | All of the registered request duration handlers. |
from Kernel |
| protected array<string, bool> | $terminableMiddleware | Whether each middleware name resolves to a terminable instance. |
from Kernel |
| protected array<int, class-string|string> | $middlewarePipelineStack | The global middleware stack represented by the reusable pipeline. |
from Kernel |
| protected Closure|null | $middlewarePipeline | The reusable global middleware pipeline. |
from Kernel |
| protected string[] | $middlewarePriority | The priority-sorted list of middleware. |
from Kernel |
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.
Perform any final actions for the request lifecycle.
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.
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.
Get the bootstrap classes for the application.
Set the application's route middleware aliases.
Set the application's middleware priority.
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 47
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 63
protected int
currentTime()
Get the current system time as a UNIX timestamp.
in
InteractsWithTime at line 71
protected string
runTimeForHumans(float $startTime, float|null $endTime = null)
Given a start time, format the total run time for human readability.
in
Kernel at line 150
__construct(Application $app, Router $router)
Create a new HTTP kernel instance.
in
Kernel at line 204
protected Response
sendRequestThroughRouter(Request $request)
Send the given request through the middleware / router.
in
Kernel at line 230
void
bootstrap()
Bootstrap the application for HTTP requests.
in
Kernel at line 245
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.
in
Kernel at line 257
void
terminate(Request $request, Response $response)
Perform any final actions for the request lifecycle.
in
Kernel at line 349
protected void
terminateMiddleware(Request $request, Response $response)
Call the terminate method on any terminable middleware.
in
Kernel at line 406
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.
in
Kernel at line 425
CarbonImmutable|null
requestStartedAt()
Get when the kernel started handling the current request.
in
Kernel at line 443
protected array
gatherRouteMiddleware(Request $request)
Gather the route middleware for the given request.
in
Kernel at line 455
protected array
parseMiddleware(string $middleware)
Parse a middleware string to get the name and parameters.
in
Kernel at line 469
bool
hasMiddleware(string $middleware)
Determine if the kernel has a given middleware.
in
Kernel at line 482
Kernel
prependMiddleware(string $middleware)
Add a new middleware to the beginning of the stack if it does not already exist.
Middleware persists in the singleton Kernel's global stack for the worker lifetime and runs on every subsequent request across all coroutines.
in
Kernel at line 500
Kernel
pushMiddleware(string $middleware)
Add a new middleware to end of the stack if it does not already exist.
Middleware persists in the singleton Kernel's global stack for the worker lifetime and runs on every subsequent request across all coroutines.
in
Kernel at line 520
Kernel
prependMiddlewareToGroup(string $group, string $middleware)
Prepend the given middleware to the given middleware group.
The middleware group persists in the singleton Kernel for the worker lifetime and runs on every subsequent request matching the group.
in
Kernel at line 546
Kernel
appendMiddlewareToGroup(string $group, string $middleware)
Append the given middleware to the given middleware group.
The middleware group persists in the singleton Kernel for the worker lifetime and runs on every subsequent request matching the group.
in
Kernel at line 571
Kernel
prependToMiddlewarePriority(string $middleware)
Prepend the given middleware to the middleware priority list.
The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.
in
Kernel at line 592
Kernel
appendToMiddlewarePriority(string $middleware)
Append the given middleware to the middleware priority list.
The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.
in
Kernel at line 614
Kernel
addToMiddlewarePriorityBefore(string|array $before, string $middleware)
Add the given middleware to the middleware priority list before other middleware.
The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.
in
Kernel at line 630
Kernel
addToMiddlewarePriorityAfter(string|array $after, string $middleware)
Add the given middleware to the middleware priority list after other middleware.
The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.
in
Kernel at line 642
protected Kernel
addToMiddlewarePriorityRelative(string|array $existing, string $middleware, bool $after = true)
Add the given middleware to the middleware priority list relative to other middleware.
in
Kernel at line 675
protected void
syncMiddlewareToRouter()
Sync the current state of the middleware to the router.
in
Kernel at line 693
array
getMiddlewarePriority()
Get the priority-sorted list of middleware.
at line 22
protected array
bootstrappers()
Get the bootstrap classes for the application.
in
Kernel at line 713
protected void
reportException(Throwable $e, array $context = [])
Report the exception to the exception handler.
in
Kernel at line 721
protected Response
renderException(Request $request, Throwable $e)
Render the exception to a response.
in
Kernel at line 731
array
getGlobalMiddleware()
Get the application's global middleware.
in
Kernel at line 745
Kernel
setGlobalMiddleware(array $middleware)
Set the application's global middleware.
Middleware persists in the singleton Kernel's global stack for the worker lifetime and runs on every subsequent request across all coroutines.
in
Kernel at line 760
array
getMiddlewareGroups()
Get the application's route middleware groups.
in
Kernel at line 774
Kernel
setMiddlewareGroups(array $groups)
Set the application's middleware groups.
Middleware groups persist in the singleton Kernel for the worker lifetime and affect every subsequent request matching those groups.
in
Kernel at line 791
array
getMiddlewareAliases()
Get the application's route middleware aliases.
in
Kernel at line 805
Kernel
setMiddlewareAliases(array $aliases)
Set the application's route middleware aliases.
Middleware aliases persist in the singleton Kernel for the worker lifetime and affect every subsequent request that uses them.
in
Kernel at line 825
Kernel
setMiddlewarePriority(array $priority)
Set the application's middleware priority.
The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.
in
Kernel at line 838
Application
getApplication()
Get the application instance.
in
Kernel at line 852
Kernel
setApplication(Application $app)
Set the application instance.
Swaps the singleton Kernel's application reference; per-request use races across coroutines and breaks every concurrent request the worker is handling.