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

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

__construct(Application $app, Router $router)

Create a new HTTP kernel instance.

from  Kernel
Response
handle(Request $request)

Handle an incoming HTTP request.

from  Kernel
Response
sendRequestThroughRouter(Request $request)

Send the given request through the middleware / router.

from  Kernel
void
bootstrap()

Bootstrap the application for HTTP requests.

from  Kernel
dispatchToRouter()

Get the route dispatcher callback.

from  Kernel
void
terminate(Request $request, Response $response)

Perform any final actions for the request lifecycle.

from  Kernel
void
terminateMiddleware(Request $request, Response $response)

Call the terminate method on any terminable middleware.

from  Kernel
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.

from  Kernel
requestStartedAt()

Get when the kernel started handling the current request.

from  Kernel
array
gatherRouteMiddleware(Request $request)

Gather the route middleware for the given request.

from  Kernel
array
parseMiddleware(string $middleware)

Parse a middleware string to get the name and parameters.

from  Kernel
bool
hasMiddleware(string $middleware)

Determine if the kernel has a given middleware.

from  Kernel
prependMiddleware(string $middleware)

Add a new middleware to the beginning of the stack if it does not already exist.

from  Kernel
pushMiddleware(string $middleware)

Add a new middleware to end of the stack if it does not already exist.

from  Kernel
prependMiddlewareToGroup(string $group, string $middleware)

Prepend the given middleware to the given middleware group.

from  Kernel
appendMiddlewareToGroup(string $group, string $middleware)

Append the given middleware to the given middleware group.

from  Kernel
prependToMiddlewarePriority(string $middleware)

Prepend the given middleware to the middleware priority list.

from  Kernel
appendToMiddlewarePriority(string $middleware)

Append the given middleware to the middleware priority list.

from  Kernel
addToMiddlewarePriorityBefore(string|array $before, string $middleware)

Add the given middleware to the middleware priority list before other middleware.

from  Kernel
addToMiddlewarePriorityAfter(string|array $after, string $middleware)

Add the given middleware to the middleware priority list after other middleware.

from  Kernel
addToMiddlewarePriorityRelative(string|array $existing, string $middleware, bool $after = true)

Add the given middleware to the middleware priority list relative to other middleware.

from  Kernel
void
syncMiddlewareToRouter()

Sync the current state of the middleware to the router.

from  Kernel
array
getMiddlewarePriority()

Get the priority-sorted list of middleware.

from  Kernel
array
bootstrappers()

Get the bootstrap classes for the application.

void
reportException(Throwable $e, array $context = [])

Report the exception to the exception handler.

from  Kernel
Response
renderException(Request $request, Throwable $e)

Render the exception to a response.

from  Kernel
array
getGlobalMiddleware()

Get the application's global middleware.

from  Kernel
setGlobalMiddleware(array $middleware)

Set the application's global middleware.

from  Kernel
array
getMiddlewareGroups()

Get the application's route middleware groups.

from  Kernel
setMiddlewareGroups(array $groups)

Set the application's middleware groups.

from  Kernel
array
getMiddlewareAliases()

Get the application's route middleware aliases.

from  Kernel
setMiddlewareAliases(array $aliases)

Set the application's route middleware aliases.

from  Kernel
setMiddlewarePriority(array $priority)

Set the application's middleware priority.

from  Kernel
getApplication()

Get the application instance.

from  Kernel
setApplication(Application $app)

Set the application instance.

from  Kernel

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

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.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 63
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

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.

Parameters

float $startTime
float|null $endTime

Return Value

string

in Kernel at line 148
__construct(Application $app, Router $router)

Create a new HTTP kernel instance.

Parameters

Application $app
Router $router

in Kernel at line 159
Response handle(Request $request)

Handle an incoming HTTP request.

Parameters

Request $request

Return Value

Response

in Kernel at line 200
protected Response sendRequestThroughRouter(Request $request)

Send the given request through the middleware / router.

Parameters

Request $request

Return Value

Response

in Kernel at line 226
void bootstrap()

Bootstrap the application for HTTP requests.

Return Value

void

in Kernel at line 241
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.

Return Value

Closure

in Kernel at line 253
void terminate(Request $request, Response $response)

Perform any final actions for the request lifecycle.

Parameters

Request $request
Response $response

Return Value

void

in Kernel at line 341
protected void terminateMiddleware(Request $request, Response $response)

Call the terminate method on any terminable middleware.

Parameters

Request $request
Response $response

Return Value

void

in Kernel at line 396
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.

Parameters

DateTimeInterface|CarbonInterval|float|int $threshold
callable $handler

Return Value

void

in Kernel at line 415
CarbonImmutable|null requestStartedAt()

Get when the kernel started handling the current request.

Return Value

CarbonImmutable|null

in Kernel at line 433
protected array gatherRouteMiddleware(Request $request)

Gather the route middleware for the given request.

Parameters

Request $request

Return Value

array

in Kernel at line 445
protected array parseMiddleware(string $middleware)

Parse a middleware string to get the name and parameters.

Parameters

string $middleware

Return Value

array

in Kernel at line 459
bool hasMiddleware(string $middleware)

Determine if the kernel has a given middleware.

Parameters

string $middleware

Return Value

bool

in Kernel at line 473
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.

Parameters

string $middleware

Return Value

Kernel

in Kernel at line 491
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.

Parameters

string $middleware

Return Value

Kernel

in Kernel at line 510
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.

Parameters

string $group
string $middleware

Return Value

Kernel

Exceptions

InvalidArgumentException

in Kernel at line 535
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.

Parameters

string $group
string $middleware

Return Value

Kernel

Exceptions

InvalidArgumentException

in Kernel at line 559
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.

Parameters

string $middleware

Return Value

Kernel

in Kernel at line 579
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.

Parameters

string $middleware

Return Value

Kernel

in Kernel at line 600
Kernel addToMiddlewarePriorityBefore(string|array $before, string $middleware)

Add the given middleware to the middleware priority list before other middleware.

Boot-only. The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.

Parameters

string|array $before
string $middleware

Return Value

Kernel

in Kernel at line 615
Kernel addToMiddlewarePriorityAfter(string|array $after, string $middleware)

Add the given middleware to the middleware priority list after other middleware.

Boot-only. The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.

Parameters

string|array $after
string $middleware

Return Value

Kernel

in Kernel at line 626
protected Kernel addToMiddlewarePriorityRelative(string|array $existing, string $middleware, bool $after = true)

Add the given middleware to the middleware priority list relative to other middleware.

Parameters

string|array $existing
string $middleware
bool $after

Return Value

Kernel

in Kernel at line 661
protected void syncMiddlewareToRouter()

Sync the current state of the middleware to the router.

Return Value

void

in Kernel at line 679
array getMiddlewarePriority()

Get the priority-sorted list of middleware.

Return Value

array

at line 22
protected array bootstrappers()

Get the bootstrap classes for the application.

Return Value

array

in Kernel at line 699
protected void reportException(Throwable $e, array $context = [])

Report the exception to the exception handler.

Parameters

Throwable $e
array $context

Return Value

void

in Kernel at line 707
protected Response renderException(Request $request, Throwable $e)

Render the exception to a response.

Parameters

Request $request
Throwable $e

Return Value

Response

in Kernel at line 717
array getGlobalMiddleware()

Get the application's global middleware.

Return Value

array

in Kernel at line 732
Kernel setGlobalMiddleware(array $middleware)

Set the application's global middleware.

Boot-only. Middleware persists in the singleton Kernel's global stack for the worker lifetime and runs on every subsequent request across all coroutines.

Parameters

array $middleware

Return Value

Kernel

in Kernel at line 746
array getMiddlewareGroups()

Get the application's route middleware groups.

Return Value

array

in Kernel at line 760
Kernel setMiddlewareGroups(array $groups)

Set the application's middleware groups.

Boot-only. Middleware groups persist in the singleton Kernel for the worker lifetime and affect every subsequent request matching those groups.

Parameters

array $groups

Return Value

Kernel

in Kernel at line 776
array getMiddlewareAliases()

Get the application's route middleware aliases.

Return Value

array

in Kernel at line 790
Kernel setMiddlewareAliases(array $aliases)

Set the application's route middleware aliases.

Boot-only. Middleware aliases persist in the singleton Kernel for the worker lifetime and affect every subsequent request that uses them.

Parameters

array $aliases

Return Value

Kernel

in Kernel at line 809
Kernel setMiddlewarePriority(array $priority)

Set the application's middleware priority.

Boot-only. The middleware priority list persists in the singleton Kernel for the worker lifetime and affects middleware ordering for every subsequent request.

Parameters

array $priority

Return Value

Kernel

in Kernel at line 821
Application getApplication()

Get the application instance.

Return Value

Application

in Kernel at line 835
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.

Parameters

Application $app

Return Value

Kernel