class GrpcRouter extends Router

internal  
 

Isolate gRPC routes while retaining Hypervel's normal dispatch machinery.

Traits

Constants

private CURRENT_ROUTE_CONTEXT_KEY

private CURRENT_REQUEST_CONTEXT_KEY

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Dispatcher $events

The event dispatcher instance.

from  Router
protected Container $container

The IoC container instance.

from  Router
protected RouteCollectionInterface $routes

The route collection instance.

from  Router
protected array<string, string> $middleware

All of the short-hand keys for middlewares.

from  Router
protected array<string, array<int, string>> $middlewareGroups

All of the middleware groups.

from  Router
array<int, string> $middlewarePriority

The priority-sorted list of middleware.

from  Router
protected Closure> $binders

The registered route value binders.

from  Router
protected array<string, string> $patterns

The globally available parameter patterns.

from  Router
protected array $groupStack

The route group attribute stack.

from  Router
protected Closure|null $implicitBindingCallback

The registered custom implicit binding callback.

from  Router
static array<int, string> $verbs

All of the verbs supported by the router.

from  Router

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

from  Tappable
__construct(Dispatcher $events, Container|null $container = null)

Create a new Router instance.

from  Router
get(string $uri, array|string|callable $action = null)

Register a new GET route with the router.

from  Router
post(string $uri, array|string|callable $action = null)

Register a new POST route with the router.

from  Router
put(string $uri, array|string|callable $action = null)

Register a new PUT route with the router.

from  Router
patch(string $uri, array|string|callable $action = null)

Register a new PATCH route with the router.

from  Router
delete(string $uri, array|string|callable $action = null)

Register a new DELETE route with the router.

from  Router
options(string $uri, array|string|callable $action = null)

Register a new OPTIONS route with the router.

from  Router
query(string $uri, array|string|callable $action = null)

Register a new QUERY route with the router.

from  Router
any(string $uri, array|string|callable|null $action = null)

Register a new route responding to all verbs.

from  Router
fallback(array|string|callable|null $action)

Register a new fallback route with the router.

from  Router
redirect(string $uri, string $destination, int $status = 302)

Create a redirect from one URI to another.

from  Router
permanentRedirect(string $uri, string $destination)

Create a permanent redirect from one URI to another.

from  Router
view(string $uri, string $view, array $data = [], int|array $status = 200, array $headers = [])

Register a new route that returns a view.

from  Router
match(array|string $methods, string $uri, array|string|callable $action = null)

Register a new route with the given verbs.

from  Router
void
resources(array $resources, array $options = [])

Register an array of resource controllers.

from  Router
void
softDeletableResources(array $resources, array $options = [])

Register an array of resource controllers that can be soft deleted.

from  Router
resource(string $name, string $controller, array $options = [])

Route a resource to a controller.

from  Router
void
apiResources(array $resources, array $options = [])

Register an array of API resource controllers.

from  Router
apiResource(string $name, string $controller, array $options = [])

Route an API resource to a controller.

from  Router
void
singletons(array $singletons, array $options = [])

Register an array of singleton resource controllers.

from  Router
singleton(string $name, string $controller, array $options = [])

Route a singleton resource to a controller.

from  Router
void
apiSingletons(array $singletons, array $options = [])

Register an array of API singleton resource controllers.

from  Router
apiSingleton(string $name, string $controller, array $options = [])

Route an API singleton resource to a controller.

from  Router
group(array $attributes, Closure|array|string $routes)

Create a route group with shared attributes.

from  Router
void
updateGroupStack(array $attributes)

Update the group stack with the given attributes.

from  Router
array
mergeWithLastGroup(array $new, bool $prependExistingPrefix = true)

Merge the given array with the last group stack.

from  Router
void
loadRoutes(Closure|string $routes)

Load the provided routes.

from  Router
string
getLastGroupPrefix()

Get the prefix from the last group on the stack.

from  Router
addRoute(array|string $methods, string $uri, array|string|callable|null $action)

Add a route to the underlying route collection.

from  Router
createRoute(array|string $methods, string $uri, mixed $action)

Create a new route instance.

from  Router
bool
actionReferencesController(mixed $action)

Determine if the action is routing to a controller.

from  Router
array
convertToControllerAction(array|string $action)

Add a controller based route action to the action array.

from  Router
string
prependGroupNamespace(string $class)

Prepend the last group namespace onto the use clause.

from  Router
string
prependGroupController(string $class)

Prepend the last group controller onto the use clause.

from  Router
newRoute(array|string $methods, string $uri, mixed $action)

Create a new Route object.

from  Router
string
prefix(string $uri)

Prefix the given URI with the last prefix.

from  Router
addWhereClausesToRoute(Route $route)

Add the necessary where clauses to the route based on its initial registration.

from  Router
void
mergeGroupAttributesIntoRoute(Route $route)

Merge the group stack with the controller action.

from  Router
Response
respondWithRoute(string $name)

Return the response returned by the given route.

from  Router
Response
dispatch(Request $request)

Dispatch the request to the application.

from  Router
Response
dispatchToRoute(Request $request)

Dispatch the request to a route and return the response.

from  Router
Response
dispatchToCallback(Request $request, Closure $callback)

Match a route, run middleware, and call the given callback instead of the controller.

from  Router
findRoute(Request $request)

Find the route matching a given request.

from  Router
Response
runRoute(Request $request, Route $route)

Return the response for the given route.

from  Router
mixed
runRouteWithinStack(Route $route, Request $request)

Run the given route within a Stack "onion" instance.

from  Router
newPipeline()

Create the middleware pipeline used to dispatch a gRPC route.

array
middlewareFor(Route $route)

Resolve user middleware while retaining mandatory protocol handling.

array
middlewareDescriptorsFor(Route $route, array $middleware)

Convert gathered middleware into descriptors, caching only the route's canonical list.

from  Router
array
describeMiddleware(array $middleware)

Convert class-string middleware into immutable pipe descriptors.

from  Router
array
gatherRouteMiddleware(Route $route)

Gather the middleware for the given route with resolved class names.

from  Router
array
resolveMiddleware(array $middleware, array $excluded = [])

Resolve a flat array of middleware classes from the provided array.

from  Router
array
resolveMiddlewareWithoutGroups(array $middleware, array $excluded = [])

Resolve middleware aliases without expanding middleware groups.

from  Router
array
resolveMiddlewareUsingGroups(array $middleware, array $excluded, array $middlewareGroups)

Resolve middleware using the given middleware groups.

from  Router
array
sortMiddleware(Collection $middlewares)

Sort the given middleware by priority.

from  Router
Response
prepareResponse(Request $request, mixed $response)

Convert a service result into a protocol-owned gRPC response.

static Response
toResponse(Request $request, mixed $response)

Static version of prepareResponse.

from  Router
substituteBindings(Route $route)

Substitute the route bindings onto the route.

from  Router
mixed
substituteImplicitBindings(Route $route)

Substitute the implicit route bindings for the given route.

from  Router
substituteImplicitBindingsUsing(callable $callback)

Register a callback to run after implicit bindings are substituted.

from  Router
mixed
performBinding(string $key, string $value, Route $route)

Call the binding callback for the given key.

from  Router
void
matched(string|callable $callback)

Register a route matched event listener.

from  Router
array
getMiddleware()

Get all of the defined middleware short-hand names.

from  Router
aliasMiddleware(string $name, string|Closure $class)

Register a short-hand name for a middleware.

from  Router
bool
hasMiddlewareGroup(string $name)

Check if a middlewareGroup with the given name exists.

from  Router
array
getMiddlewareGroups()

Get all of the defined middleware groups.

from  Router
middlewareGroup(string $name, array $middleware)

Register a group of middleware.

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

Add a middleware to the beginning of a middleware group.

from  Router
pushMiddlewareToGroup(string $group, string $middleware)

Add a middleware to the end of a middleware group.

from  Router
removeMiddlewareFromGroup(string $group, string|array $middleware)

Remove the given middleware from the specified group.

from  Router
flushMiddlewareGroups()

Flush the router's middleware groups.

from  Router
void
bind(string $key, string|callable $binder)

Add a new route parameter binder.

from  Router
void
model(string $key, string $class, Closure|null $callback = null)

Register a model binder for a wildcard.

from  Router
Closure|null
getBindingCallback(string $key)

Get the binding callback for a given binding.

from  Router
array
getPatterns()

Get the global "where" patterns.

from  Router
void
pattern(string $key, string $pattern)

Set a global where pattern on all routes.

from  Router
void
patterns(array $patterns)

Set a group of global where patterns on all routes.

from  Router
bool
hasGroupStack()

Determine if the router currently has a group stack.

from  Router
array
getGroupStack()

Get the current group stack for the router.

from  Router
mixed
input(string $key, string|null $default = null)

Get a route parameter for the current route.

from  Router
Request|null
getCurrentRequest()

Get the request currently being dispatched.

from  Router
Route|null
getCurrentRoute()

Get the currently dispatched route instance.

from  Router
Route|null
current()

Get the currently dispatched route instance.

from  Router
bool
has(string|array $name)

Check if a route with the given name exists.

from  Router
string|null
currentRouteName()

Get the current route name.

from  Router
bool
is(mixed ...$patterns)

Alias for the "currentRouteNamed" method.

from  Router
bool
currentRouteNamed(mixed ...$patterns)

Determine if the current route matches a pattern.

from  Router
string|null
currentRouteAction()

Get the current route action.

from  Router
bool
uses(array|string ...$patterns)

Alias for the "currentRouteUses" method.

from  Router
bool
currentRouteUses(string $action)

Determine if the current route action matches a given action.

from  Router
void
singularResourceParameters(bool $singular = true)

Set the unmapped global resource parameters to singular.

from  Router
void
resourceParameters(array $parameters = [])

Set the global resource parameter mapping.

from  Router
array|null
resourceVerbs(array $verbs = [])

Get or set the verbs used in the resource URIs.

from  Router
getRoutes()

Get the underlying route collection.

from  Router
void
setRoutes(RouteCollection $routes)

Set the route collection instance.

from  Router
void
setCompiledRoutes(array $routes)

Set the compiled route collection instance.

from  Router
bool
ownsGlobalRouteState()

Determine whether this router owns the application's global route state.

void
flushRoutingCaches()

Flush all static routing caches.

from  Router
void
compileAndWarm()

Validate gRPC route actions before compiling and warming the collection.

void
warmUp()

Pre-warm all caches for the registered routes.

from  Router
static array
uniqueMiddleware(array $middleware)

Remove any duplicate middleware from the given array.

from  Router
setContainer(Container $container)

Set the container instance used by the router.

from  Router
static void
flushState()

Flush all static state.

from  Router
void
syncMiddlewareFrom(Router $router)

Synchronize application route middleware before worker warmup.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Tappable at line 17
mixed tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

Parameters

callable|null $callback

Return Value

mixed

in Router at line 128
__construct(Dispatcher $events, Container|null $container = null)

Create a new Router instance.

Parameters

Dispatcher $events
Container|null $container

in Router at line 138
Route get(string $uri, array|string|callable $action = null)

Register a new GET route with the router.

Parameters

string $uri
array|string|callable $action

Return Value

Route

in Router at line 146
Route post(string $uri, array|string|callable $action = null)

Register a new POST route with the router.

Parameters

string $uri
array|string|callable $action

Return Value

Route

in Router at line 154
Route put(string $uri, array|string|callable $action = null)

Register a new PUT route with the router.

Parameters

string $uri
array|string|callable $action

Return Value

Route

in Router at line 162
Route patch(string $uri, array|string|callable $action = null)

Register a new PATCH route with the router.

Parameters

string $uri
array|string|callable $action

Return Value

Route

in Router at line 170
Route delete(string $uri, array|string|callable $action = null)

Register a new DELETE route with the router.

Parameters

string $uri
array|string|callable $action

Return Value

Route

in Router at line 178
Route options(string $uri, array|string|callable $action = null)

Register a new OPTIONS route with the router.

Parameters

string $uri
array|string|callable $action

Return Value

Route

in Router at line 186
Route query(string $uri, array|string|callable $action = null)

Register a new QUERY route with the router.

Parameters

string $uri
array|string|callable $action

Return Value

Route

in Router at line 194
Route any(string $uri, array|string|callable|null $action = null)

Register a new route responding to all verbs.

Parameters

string $uri
array|string|callable|null $action

Return Value

Route

in Router at line 202
Route fallback(array|string|callable|null $action)

Register a new fallback route with the router.

Parameters

array|string|callable|null $action

Return Value

Route

in Router at line 216
Route redirect(string $uri, string $destination, int $status = 302)

Create a redirect from one URI to another.

Parameters

string $uri
string $destination
int $status

Return Value

Route

in Router at line 226
Route permanentRedirect(string $uri, string $destination)

Create a permanent redirect from one URI to another.

Parameters

string $uri
string $destination

Return Value

Route

in Router at line 234
Route view(string $uri, string $view, array $data = [], int|array $status = 200, array $headers = [])

Register a new route that returns a view.

Parameters

string $uri
string $view
array $data
int|array $status
array $headers

Return Value

Route

in Router at line 248
Route match(array|string $methods, string $uri, array|string|callable $action = null)

Register a new route with the given verbs.

Parameters

array|string $methods
string $uri
array|string|callable $action

Return Value

Route

in Router at line 256
void resources(array $resources, array $options = [])

Register an array of resource controllers.

Parameters

array $resources
array $options

Return Value

void

in Router at line 266
void softDeletableResources(array $resources, array $options = [])

Register an array of resource controllers that can be soft deleted.

Parameters

array $resources
array $options

Return Value

void

in Router at line 276
PendingResourceRegistration resource(string $name, string $controller, array $options = [])

Route a resource to a controller.

Parameters

string $name
string $controller
array $options

Return Value

PendingResourceRegistration

in Router at line 295
void apiResources(array $resources, array $options = [])

Register an array of API resource controllers.

Parameters

array $resources
array $options

Return Value

void

in Router at line 305
PendingResourceRegistration apiResource(string $name, string $controller, array $options = [])

Route an API resource to a controller.

Parameters

string $name
string $controller
array $options

Return Value

PendingResourceRegistration

in Router at line 321
void singletons(array $singletons, array $options = [])

Register an array of singleton resource controllers.

Parameters

array $singletons
array $options

Return Value

void

in Router at line 331
PendingSingletonResourceRegistration singleton(string $name, string $controller, array $options = [])

Route a singleton resource to a controller.

Parameters

string $name
string $controller
array $options

Return Value

PendingSingletonResourceRegistration

in Router at line 350
void apiSingletons(array $singletons, array $options = [])

Register an array of API singleton resource controllers.

Parameters

array $singletons
array $options

Return Value

void

in Router at line 360
PendingSingletonResourceRegistration apiSingleton(string $name, string $controller, array $options = [])

Route an API singleton resource to a controller.

Parameters

string $name
string $controller
array $options

Return Value

PendingSingletonResourceRegistration

in Router at line 378
Registrar group(array $attributes, Closure|array|string $routes)

Create a route group with shared attributes.

Parameters

array $attributes
Closure|array|string $routes

Return Value

Registrar

in Router at line 399
protected void updateGroupStack(array $attributes)

Update the group stack with the given attributes.

Parameters

array $attributes

Return Value

void

in Router at line 411
array mergeWithLastGroup(array $new, bool $prependExistingPrefix = true)

Merge the given array with the last group stack.

Parameters

array $new
bool $prependExistingPrefix

Return Value

array

in Router at line 419
protected void loadRoutes(Closure|string $routes)

Load the provided routes.

Parameters

Closure|string $routes

Return Value

void

in Router at line 431
string getLastGroupPrefix()

Get the prefix from the last group on the stack.

Return Value

string

in Router at line 445
Route addRoute(array|string $methods, string $uri, array|string|callable|null $action)

Add a route to the underlying route collection.

Parameters

array|string $methods
string $uri
array|string|callable|null $action

Return Value

Route

in Router at line 453
protected Route createRoute(array|string $methods, string $uri, mixed $action)

Create a new route instance.

Parameters

array|string $methods
string $uri
mixed $action

Return Value

Route

in Router at line 483
protected bool actionReferencesController(mixed $action)

Determine if the action is routing to a controller.

Parameters

mixed $action

Return Value

bool

in Router at line 496
protected array convertToControllerAction(array|string $action)

Add a controller based route action to the action array.

Parameters

array|string $action

Return Value

array

in Router at line 521
protected string prependGroupNamespace(string $class)

Prepend the last group namespace onto the use clause.

Parameters

string $class

Return Value

string

in Router at line 533
protected string prependGroupController(string $class)

Prepend the last group controller onto the use clause.

Parameters

string $class

Return Value

string

in Router at line 555
Route newRoute(array|string $methods, string $uri, mixed $action)

Create a new Route object.

Parameters

array|string $methods
string $uri
mixed $action

Return Value

Route

in Router at line 565
protected string prefix(string $uri)

Prefix the given URI with the last prefix.

Parameters

string $uri

Return Value

string

in Router at line 573
protected Route addWhereClausesToRoute(Route $route)

Add the necessary where clauses to the route based on its initial registration.

Parameters

Route $route

Return Value

Route

in Router at line 586
protected void mergeGroupAttributesIntoRoute(Route $route)

Merge the group stack with the controller action.

Parameters

Route $route

Return Value

void

in Router at line 597
Response respondWithRoute(string $name)

Return the response returned by the given route.

Parameters

string $name

Return Value

Response

in Router at line 609
Response dispatch(Request $request)

Dispatch the request to the application.

Parameters

Request $request

Return Value

Response

in Router at line 619
Response dispatchToRoute(Request $request)

Dispatch the request to a route and return the response.

Parameters

Request $request

Return Value

Response

in Router at line 634
Response dispatchToCallback(Request $request, Closure $callback)

Match a route, run middleware, and call the given callback instead of the controller.

Performs the full route context lifecycle (route matching, context setup, route resolver, RouteMatched event, middleware pipeline) but calls the provided callback as the terminal handler instead of the route's action.

Used by the WebSocket server for handshake requests where route matching and middleware must run but the controller must not be invoked.

Parameters

Request $request
Closure $callback

Return Value

Response

in Router at line 658
protected Route findRoute(Request $request)

Find the route matching a given request.

Parameters

Request $request

Return Value

Route

in Router at line 676
protected Response runRoute(Request $request, Route $route)

Return the response for the given route.

Parameters

Request $request
Route $route

Return Value

Response

in Router at line 693
protected mixed runRouteWithinStack(Route $route, Request $request)

Run the given route within a Stack "onion" instance.

Parameters

Route $route
Request $request

Return Value

mixed

at line 268
protected Pipeline newPipeline()

Create the middleware pipeline used to dispatch a gRPC route.

Return Value

Pipeline

at line 276
protected array middlewareFor(Route $route)

Resolve user middleware while retaining mandatory protocol handling.

Parameters

Route $route

Return Value

array

in Router at line 749
protected array middlewareDescriptorsFor(Route $route, array $middleware)

Convert gathered middleware into descriptors, caching only the route's canonical list.

Parameters

Route $route
array $middleware

Return Value

array

in Router at line 769
protected array describeMiddleware(array $middleware)

Convert class-string middleware into immutable pipe descriptors.

Parameters

array $middleware

Return Value

array

in Router at line 784
array gatherRouteMiddleware(Route $route)

Gather the middleware for the given route with resolved class names.

Parameters

Route $route

Return Value

array

in Router at line 797
array resolveMiddleware(array $middleware, array $excluded = [])

Resolve a flat array of middleware classes from the provided array.

Parameters

array $middleware
array $excluded

Return Value

array

in Router at line 807
array resolveMiddlewareWithoutGroups(array $middleware, array $excluded = [])

Resolve middleware aliases without expanding middleware groups.

Parameters

array $middleware
array $excluded

Return Value

array

in Router at line 817
protected array resolveMiddlewareUsingGroups(array $middleware, array $excluded, array $middlewareGroups)

Resolve middleware using the given middleware groups.

Parameters

array $middleware
array $excluded
array $middlewareGroups

Return Value

array

in Router at line 862
protected array sortMiddleware(Collection $middlewares)

Sort the given middleware by priority.

Parameters

Collection $middlewares

Return Value

array

at line 140
Response prepareResponse(Request $request, mixed $response)

Convert a service result into a protocol-owned gRPC response.

Parameters

Request $request
mixed $response

Return Value

Response

in Router at line 888
static Response toResponse(Request $request, mixed $response)

Static version of prepareResponse.

Parameters

Request $request
mixed $response

Return Value

Response

in Router at line 925
Route substituteBindings(Route $route)

Substitute the route bindings onto the route.

Parameters

Route $route

Return Value

Route

Exceptions

Model>
BackedEnumCaseNotFoundException

in Router at line 942
mixed substituteImplicitBindings(Route $route)

Substitute the implicit route bindings for the given route.

Parameters

Route $route

Return Value

mixed

Exceptions

Model>
BackedEnumCaseNotFoundException

in Router at line 962
Router substituteImplicitBindingsUsing(callable $callback)

Register a callback to run after implicit bindings are substituted.

Boot-only. The callback persists on the singleton Router and affects every subsequent route binding.

Parameters

callable $callback

Return Value

Router

in Router at line 974
protected mixed performBinding(string $key, string $value, Route $route)

Call the binding callback for the given key.

Parameters

string $key
string $value
Route $route

Return Value

mixed

Exceptions

Model>

in Router at line 985
void matched(string|callable $callback)

Register a route matched event listener.

Boot-only. The listener persists on the worker-lifetime event dispatcher and runs for every subsequent route match.

Parameters

string|callable $callback

Return Value

void

in Router at line 995
array getMiddleware()

Get all of the defined middleware short-hand names.

Return Value

array

in Router at line 1008
Router aliasMiddleware(string $name, string|Closure $class)

Register a short-hand name for a middleware.

Boot-only. The alias persists in the singleton Router for the worker lifetime and applies to every subsequent route resolution.

Parameters

string $name
string|Closure $class

Return Value

Router

in Router at line 1018
bool hasMiddlewareGroup(string $name)

Check if a middlewareGroup with the given name exists.

Parameters

string $name

Return Value

bool

in Router at line 1028
array getMiddlewareGroups()

Get all of the defined middleware groups.

Return Value

array

in Router at line 1041
Router middlewareGroup(string $name, array $middleware)

Register a group of middleware.

Boot-only. The middleware group persists in the singleton Router for the worker lifetime and applies to every subsequent route resolution.

Parameters

string $name
array $middleware

Return Value

Router

in Router at line 1058
Router prependMiddlewareToGroup(string $group, string $middleware)

Add a middleware to the beginning of a middleware group.

If the middleware is already in the group, it will not be added again.

Boot-only. The middleware group persists in the singleton Router for the worker lifetime and applies to every subsequent route resolution.

Parameters

string $group
string $middleware

Return Value

Router

in Router at line 1077
Router pushMiddlewareToGroup(string $group, string $middleware)

Add a middleware to the end of a middleware group.

If the middleware is already in the group, it will not be added again.

Boot-only. The middleware group persists in the singleton Router for the worker lifetime and applies to every subsequent route resolution.

Parameters

string $group
string $middleware

Return Value

Router

in Router at line 1098
Router removeMiddlewareFromGroup(string $group, string|array $middleware)

Remove the given middleware from the specified group.

Boot-only. The group mutation persists on the singleton Router and does not invalidate middleware already resolved on routes.

Parameters

string $group
string|array $middleware

Return Value

Router

in Router at line 1128
Router flushMiddlewareGroups()

Flush the router's middleware groups.

Boot or tests only. Clears the singleton Router's middleware-group registry shared by every coroutine; concurrent requests lose middleware mid-dispatch.

Return Value

Router

in Router at line 1141
void bind(string $key, string|callable $binder)

Add a new route parameter binder.

Boot-only. The binder persists in the singleton Router for the worker lifetime and runs on every subsequent route parameter resolution.

Parameters

string $key
string|callable $binder

Return Value

void

in Router at line 1155
void model(string $key, string $class, Closure|null $callback = null)

Register a model binder for a wildcard.

Boot-only. The model binder persists in the singleton Router for the worker lifetime and runs on every subsequent route parameter resolution.

Parameters

string $key
string $class
Closure|null $callback

Return Value

void

in Router at line 1163
Closure|null getBindingCallback(string $key)

Get the binding callback for a given binding.

Parameters

string $key

Return Value

Closure|null

in Router at line 1177
array getPatterns()

Get the global "where" patterns.

Return Value

array

in Router at line 1188
void pattern(string $key, string $pattern)

Set a global where pattern on all routes.

Boot-only. The pattern persists in the singleton Router for the worker lifetime and applies to every subsequent route definition.

Parameters

string $key
string $pattern

Return Value

void

in Router at line 1199
void patterns(array $patterns)

Set a group of global where patterns on all routes.

Boot-only. The patterns persist in the singleton Router for the worker lifetime and apply to every subsequent route definition.

Parameters

array $patterns

Return Value

void

in Router at line 1209
bool hasGroupStack()

Determine if the router currently has a group stack.

Return Value

bool

in Router at line 1217
array getGroupStack()

Get the current group stack for the router.

Return Value

array

in Router at line 1225
mixed input(string $key, string|null $default = null)

Get a route parameter for the current route.

Parameters

string $key
string|null $default

Return Value

mixed

in Router at line 1233
Request|null getCurrentRequest()

Get the request currently being dispatched.

Return Value

Request|null

in Router at line 1241
Route|null getCurrentRoute()

Get the currently dispatched route instance.

Return Value

Route|null

in Router at line 1249
Route|null current()

Get the currently dispatched route instance.

Return Value

Route|null

in Router at line 1257
bool has(string|array $name)

Check if a route with the given name exists.

Parameters

string|array $name

Return Value

bool

in Router at line 1274
string|null currentRouteName()

Get the current route name.

Return Value

string|null

in Router at line 1282
bool is(mixed ...$patterns)

Alias for the "currentRouteNamed" method.

Parameters

mixed ...$patterns

Return Value

bool

in Router at line 1290
bool currentRouteNamed(mixed ...$patterns)

Determine if the current route matches a pattern.

Parameters

mixed ...$patterns

Return Value

bool

in Router at line 1298
string|null currentRouteAction()

Get the current route action.

Return Value

string|null

in Router at line 1310
bool uses(array|string ...$patterns)

Alias for the "currentRouteUses" method.

Parameters

array|string ...$patterns

Return Value

bool

in Router at line 1325
bool currentRouteUses(string $action)

Determine if the current route action matches a given action.

Parameters

string $action

Return Value

bool

in Router at line 1336
void singularResourceParameters(bool $singular = true)

Set the unmapped global resource parameters to singular.

Boot-only. Delegates to ResourceRegistrar::singularParameters() which persists in a static property for the worker lifetime.

Parameters

bool $singular

Return Value

void

in Router at line 1346
void resourceParameters(array $parameters = [])

Set the global resource parameter mapping.

Boot-only. The mapping persists in static state for the worker lifetime.

Parameters

array $parameters

Return Value

void

in Router at line 1357
array|null resourceVerbs(array $verbs = [])

Get or set the verbs used in the resource URIs.

Boot-only when setting. Custom verbs persist in static state for the worker lifetime.

Parameters

array $verbs

Return Value

array|null

in Router at line 1365
RouteCollectionInterface getRoutes()

Get the underlying route collection.

in Router at line 1376
void setRoutes(RouteCollection $routes)

Set the route collection instance.

Boot or tests only. Replacing the collection mutates the singleton Router and its shared route binding for every subsequent request.

Parameters

RouteCollection $routes

Return Value

void

in Router at line 1400
void setCompiledRoutes(array $routes)

Set the compiled route collection instance.

Boot-only. Replaces the singleton Router's route collection and rebinds the container's 'routes' instance; runtime use breaks every concurrent request mid-dispatch.

Parameters

array $routes

Return Value

void

at line 284
protected bool ownsGlobalRouteState()

Determine whether this router owns the application's global route state.

Return Value

bool

in Router at line 1429
protected void flushRoutingCaches()

Flush all static routing caches.

Called when the route collection is replaced to clear stale data. In Swoole workers live forever, so stale statics would persist.

Return Value

void

at line 54
void compileAndWarm()

Validate gRPC route actions before compiling and warming the collection.

Return Value

void

in Router at line 1471
void warmUp()

Pre-warm all caches for the registered routes.

Eagerly populates route compilation, middleware resolution, and reflection caches so they're available before fork. Workers inherit via copy-on-write in both SWOOLE_PROCESS and SWOOLE_BASE modes.

Return Value

void

in Router at line 1516
static array uniqueMiddleware(array $middleware)

Remove any duplicate middleware from the given array.

Parameters

array $middleware

Return Value

array

in Router at line 1541
Router setContainer(Container $container)

Set the container instance used by the router.

Tests only. Swaps the singleton Router's container reference; per-request use races across coroutines and breaks every concurrent route dispatch.

Parameters

Container $container

Return Value

Router

in Router at line 1551
static void flushState()

Flush all static state.

Return Value

void

at line 38
void syncMiddlewareFrom(Router $router)

internal  
 

Synchronize application route middleware before worker warmup.

Parameters

Router $router

Return Value

void