Skip to content
PHP Ecosystem
Explore

RouteDefinition

API reference › Debug Core › Panel › Request › Routing › RouteDefinition

final classPHPForge\Debug\Panel\Request\Routing\RouteDefinition
Sourcesrc/Panel/Request/Routing/RouteDefinition.php

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.

MethodDescriptionDefined by
__construct()Creates persistence-safe route metadata.RouteDefinition
create() staticCreates a route definition ready for immutable enrichment.RouteDefinition
fromArray() staticRestores 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
public function __construct(string $name = '', string $pattern = '')

Creates persistence-safe route metadata.

Parameters

ParameterTypeDescription
$namestringRoute name as the application declares it.
$patternstringURL pattern the route matches.
public static function create(string $name = '', string $pattern = ''): self

Creates a route definition ready for immutable enrichment.

Parameters

ParameterTypeDescription
$namestringRoute name as the application declares it.
$patternstringURL pattern the route matches.

Returns

self: Definition carrying only the route identity.

public static function fromArray(array<array-key, mixed> $data): self

Restores 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

ParameterTypeDescription
$dataarray<array-key, mixed>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.
public function getAction(): string|null

Returns the handler the route dispatches to.

Returns

string|null: Handler the route dispatches to, or null when unsupported.

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.

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.

public function getMiddlewares(): list<string>|null

Returns 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.

public function getMode(): string|null

Returns the parsing mode the rule runs in.

Returns

string|null: Parsing mode the rule runs in, or null when unsupported.

public function getName(): string

Returns the route name.

Returns

string: Route name as the application declares it.

public function getPattern(): string

Returns the URL pattern the route matches.

Returns

string: URL pattern the route matches.

public function getSuffix(): string|null

Returns the URL suffix the rule appends.

Returns

string|null: URL suffix the rule appends, or null when unsupported.

public function getTarget(): string|null

Returns the route the rule resolves to.

Returns

string|null: Route the rule resolves to, or null when unsupported.

public function getType(): string|null

Returns the rule class or category.

Returns

string|null: Rule class or category reported by the adapter, or null when unsupported.

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.

public function withAction(string|null $action): self

Returns a copy carrying another action.

Parameters

ParameterTypeDescription
$actionstring|nullHandler the route dispatches to, or null when unsupported.

Returns

self: Definition with the action applied.

public function withHosts(list<string> $hosts): self

Returns a copy restricted to another set of hosts.

Parameters

ParameterTypeDescription
$hostslist<string>Hosts the route is restricted to; empty to leave it unrestricted.

Returns

self: Definition with the hosts applied.

public function withMethods(list<string> $methods): self

Returns a copy accepting another set of HTTP methods.

Parameters

ParameterTypeDescription
$methodslist<string>HTTP methods the route accepts; empty to accept any.

Returns

self: Definition with the methods applied.

public function withMiddlewares(list<string>|null $middlewares): self

Returns a copy carrying another middleware chain.

Parameters

ParameterTypeDescription
$middlewareslist<string>|nullMiddleware labels applied to the route; empty when it has none, or null when unsupported.

Returns

self: Definition with the middlewares applied.

public function withMode(string|null $mode): self

Returns a copy carrying another mode.

Parameters

ParameterTypeDescription
$modestring|nullParsing mode the rule runs in, or null when unsupported.

Returns

self: Definition with the mode applied.

public function withSuffix(string|null $suffix): self

Returns a copy carrying another suffix.

Parameters

ParameterTypeDescription
$suffixstring|nullURL suffix the rule appends, or null when unsupported.

Returns

self: Definition with the suffix applied.

public function withTarget(string|null $target): self

Returns a copy carrying another target.

Parameters

ParameterTypeDescription
$targetstring|nullRoute the rule resolves to, or null when unsupported.

Returns

self: Definition with the target applied.

public function withType(string|null $type): self

Returns a copy carrying another type.

Parameters

ParameterTypeDescription
$typestring|nullRule class or category reported by the adapter, or null when unsupported.

Returns

self: Definition with the type applied.