class RouteDefinition (View source)

Definitions for a specific route.

Constants

DYNAMIC_SEGMENT

Value used to indicate a segment is dynamic rather than static

Methods

__construct(string $name, array $methods, string $path, mixed $handler)

RouteDefinition constructor.

static RouteDefinition
createFromCache(array $cache)

Returns a new RouteDefinition instance based on the cached values.

array
getDefinitionCache()

Returns cached values for the RouteDefinition that can be used to instantiate a new RouteDefinition.

string
getName()

Returns the name of the route.

array
getMethods()

Returns the allowed methods for the route.

array
getSegments()

Returns the static segments for the route.

mixed
getHandler()

Returns the route handler.

bool
hasSlash()

Tells if the canonical route path ends in a forward slash or not.

bool
isStatic()

Tells if the path is completely static without any dynamic segments.

bool
matchPatterns(array $segments, array $values)

Matches the given segments against the dynamic path segments.

bool
isMethodAllowed(string $method)

Tells if the given HTTP request method is allowed by the route.

string
formatUrl(array $parameters = [])

Returns an encoded URL for the route based on the given parameter values.

Details

__construct(string $name, array $methods, string $path, mixed $handler)

RouteDefinition constructor.

Parameters

string $name Name of the route
array $methods Allowed HTTP request methods for the route
string $path Path definition for the route
mixed $handler Handler for route

static RouteDefinition createFromCache(array $cache)

Returns a new RouteDefinition instance based on the cached values.

Parameters

array $cache The cached RouteDefinition values

Return Value

RouteDefinition A new RouteDefinition instance

array getDefinitionCache()

Returns cached values for the RouteDefinition that can be used to instantiate a new RouteDefinition.

Return Value

array RouteDefinition cache values

string getName()

Returns the name of the route.

Return Value

string The name of the route

array getMethods()

Returns the allowed methods for the route.

Return Value

array The allowed methods for the route

array getSegments()

Returns the static segments for the route.

Return Value

array The static segments for the route

mixed getHandler()

Returns the route handler.

Return Value

mixed The route handler

bool hasSlash()

Tells if the canonical route path ends in a forward slash or not.

Return Value

bool True if the path ends in a slash, false if not

bool isStatic()

Tells if the path is completely static without any dynamic segments.

Return Value

bool True if the path is static, false if not

bool matchPatterns(array $segments, array $values)

Matches the given segments against the dynamic path segments.

Parameters

array $segments The segments to match against
array $values Array that will be populated with route parameter values on match

Return Value

bool True if the dynamic segments match, false if not

bool isMethodAllowed(string $method)

Tells if the given HTTP request method is allowed by the route.

Parameters

string $method The HTTP request method to test

Return Value

bool True if the given HTTP request method is allowed, false if not

string formatUrl(array $parameters = [])

Returns an encoded URL for the route based on the given parameter values.

Parameters

array $parameters Values for the route parameters

Return Value

string The encoded URL for the route