RouteDefinition
API reference › Debug Core › Panel › Request › Routing › RouteDefinition
Immutable, persistence-safe route metadata shared by framework adapters.
A null optional value means the adapter cannot expose that concept. An empty methods or hosts list means the route
is unrestricted, while an empty middleware list means the route has no middleware.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates persistence-safe route metadata. | RouteDefinition |
create() static | Creates a route definition ready for immutable enrichment. | RouteDefinition |
fromArray() static | Restores a route definition from its strict scalar persistence shape. | RouteDefinition |
getAction() | Returns the handler the route dispatches to. | RouteDefinition |
getHosts() | Returns the hosts the route is restricted to. | RouteDefinition |
getMethods() | Returns the HTTP methods the route accepts. | RouteDefinition |
getMiddlewares() | Returns the middleware chain applied to the route. | RouteDefinition |
getMode() | Returns the parsing mode the rule runs in. | RouteDefinition |
getName() | Returns the route name. | RouteDefinition |
getPattern() | Returns the URL pattern the route matches. | RouteDefinition |
getSuffix() | Returns the URL suffix the rule appends. | RouteDefinition |
getTarget() | Returns the route the rule resolves to. | RouteDefinition |
getType() | Returns the rule class or category. | RouteDefinition |
toArray() | Returns the compact route persistence shape used in Request snapshots. | RouteDefinition |
withAction() | Returns a copy carrying another action. | RouteDefinition |
withHosts() | Returns a copy restricted to another set of hosts. | RouteDefinition |
withMethods() | Returns a copy accepting another set of HTTP methods. | RouteDefinition |
withMiddlewares() | Returns a copy carrying another middleware chain. | RouteDefinition |
withMode() | Returns a copy carrying another mode. | RouteDefinition |
withSuffix() | Returns a copy carrying another suffix. | RouteDefinition |
withTarget() | Returns a copy carrying another target. | RouteDefinition |
withType() | Returns a copy carrying another type. | RouteDefinition |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(string $name = '', string $pattern = '')Creates persistence-safe route metadata.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Route name as the application declares it. |
$pattern | string | URL pattern the route matches. |
create()
Section titled “create() ”public static function create(string $name = '', string $pattern = ''): selfCreates a route definition ready for immutable enrichment.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Route name as the application declares it. |
$pattern | string | URL pattern the route matches. |
Returns
self: Definition carrying only the route identity.
fromArray()
Section titled “fromArray() ”public static function fromArray(array<array-key, mixed> $data): selfRestores a route definition from its strict scalar persistence shape.
The six Yii 3 fields are required for compatibility with existing captures. Yii 2-specific fields remain optional so old snapshots keep hydrating without schema migration.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array<array-key, | Persisted route definition. |
Returns
self: Definition restored from the persisted shape.
Throws
InvalidArgumentException: when a required field is missing, a field is declared but unknown, or a value does not match its persisted type.
getAction()
Section titled “getAction() ”public function getAction(): string|nullReturns the handler the route dispatches to.
Returns
string|null: Handler the route dispatches to, or null when unsupported.
getHosts()
Section titled “getHosts() ”public function getHosts(): list<string>Returns the hosts the route is restricted to.
Returns
list<string>: Hosts the route is restricted to; empty when it is unrestricted.
getMethods()
Section titled “getMethods() ”public function getMethods(): list<string>Returns the HTTP methods the route accepts.
Returns
list<string>: HTTP methods the route accepts; empty when it accepts any.
getMiddlewares()
Section titled “getMiddlewares() ”public function getMiddlewares(): list<string>|nullReturns the middleware chain applied to the route.
Returns
list<string>|null: Middleware labels applied to the route; empty when it has none, or null when unsupported.
getMode()
Section titled “getMode() ”public function getMode(): string|nullReturns the parsing mode the rule runs in.
Returns
string|null: Parsing mode the rule runs in, or null when unsupported.
getName()
Section titled “getName() ”public function getName(): stringReturns the route name.
Returns
string: Route name as the application declares it.
getPattern()
Section titled “getPattern() ”public function getPattern(): stringReturns the URL pattern the route matches.
Returns
string: URL pattern the route matches.
getSuffix()
Section titled “getSuffix() ”public function getSuffix(): string|nullReturns the URL suffix the rule appends.
Returns
string|null: URL suffix the rule appends, or null when unsupported.
getTarget()
Section titled “getTarget() ”public function getTarget(): string|nullReturns the route the rule resolves to.
Returns
string|null: Route the rule resolves to, or null when unsupported.
getType()
Section titled “getType() ”public function getType(): string|nullReturns the rule class or category.
Returns
string|null: Rule class or category reported by the adapter, or null when unsupported.
toArray()
Section titled “toArray() ”public function toArray(): array{name: string, pattern: string, methods: list<string>, hosts: list<string>, action: string|null, middlewares: list<string>|null, target?: string, suffix?: string, mode?: string, type?: string}Returns the compact route persistence shape used in Request snapshots.
Returns
array{name: string, pattern: string, methods: list<string>, hosts: list<string>, action: string|null, middlewares: list<string>|null, target?: string, suffix?: string, mode?: string, type?: string}: Route fields; the optional ones appear only when the adapter exposed them.
withAction()
Section titled “withAction() ”public function withAction(string|null $action): selfReturns a copy carrying another action.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | string| | Handler the route dispatches to, or null when unsupported. |
Returns
self: Definition with the action applied.
withHosts()
Section titled “withHosts() ”public function withHosts(list<string> $hosts): selfReturns a copy restricted to another set of hosts.
Parameters
| Parameter | Type | Description |
|---|---|---|
$hosts | list<string> | Hosts the route is restricted to; empty to leave it unrestricted. |
Returns
self: Definition with the hosts applied.
withMethods()
Section titled “withMethods() ”public function withMethods(list<string> $methods): selfReturns a copy accepting another set of HTTP methods.
Parameters
| Parameter | Type | Description |
|---|---|---|
$methods | list<string> | HTTP methods the route accepts; empty to accept any. |
Returns
self: Definition with the methods applied.
withMiddlewares()
Section titled “withMiddlewares() ”public function withMiddlewares(list<string>|null $middlewares): selfReturns a copy carrying another middleware chain.
Parameters
| Parameter | Type | Description |
|---|---|---|
$middlewares | list<string>| | Middleware labels applied to the route; empty when it has none, or null when unsupported. |
Returns
self: Definition with the middlewares applied.
withMode()
Section titled “withMode() ”public function withMode(string|null $mode): selfReturns a copy carrying another mode.
Parameters
| Parameter | Type | Description |
|---|---|---|
$mode | string| | Parsing mode the rule runs in, or null when unsupported. |
Returns
self: Definition with the mode applied.
withSuffix()
Section titled “withSuffix() ”public function withSuffix(string|null $suffix): selfReturns a copy carrying another suffix.
Parameters
| Parameter | Type | Description |
|---|---|---|
$suffix | string| | URL suffix the rule appends, or null when unsupported. |
Returns
self: Definition with the suffix applied.
withTarget()
Section titled “withTarget() ”public function withTarget(string|null $target): selfReturns a copy carrying another target.
Parameters
| Parameter | Type | Description |
|---|---|---|
$target | string| | Route the rule resolves to, or null when unsupported. |
Returns
self: Definition with the target applied.
withType()
Section titled “withType() ”public function withType(string|null $type): selfReturns a copy carrying another type.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | string| | Rule class or category reported by the adapter, or null when unsupported. |
Returns
self: Definition with the type applied.