\Omega\Routing Route

Route class.

The Route class represents an individual route in the routing system.

Summary

Methods
Properties
Constants
__construct
getMethod
getPath
getParameters
getName
name
matches
dispatch
No public properties found
No public constants found
No protected methods found
parameters
method
path
handler
name
No protected constants found
normalisePath
No private properties found
No private constants found

Properties

$parameters

$parameters : array

Array of route parameters.

Type

array<string|int, mixed> — Holds an array of route parameters.

$method

$method : string

Type

string

$path

$path : string

Type

string

$handler

$handler : mixed

Type

mixed

$name

$name : ?string

Type

string|null

Methods

__construct()

__construct(string  $method, string  $path, mixed  $handler, string|null  $name = null) : void

Route class constructor.

Parameters

string $method

Holds the HTTP method associated with the route.

string $path

Holds the path pattern for the route.

mixed $handler

Holds the handler for the route.

string|null $name

Holds the route name or null.

Returns

void —

getMethod()

getMethod() : string

Get the HTTP method associated with the route.

Returns

string —

Returns the route method.

getPath()

getPath() : string

Get the path pattern for the route.

Returns

string —

Returns the route path.

getParameters()

getParameters() : array

Get the parameters associated with the route.

Returns

array —

Returns an array of route parameters.

getName()

getName(string|null  $name = null) : $this|string|null

Get or set the name of the route.

Parameters

string|null $name

Holds the route name.

Returns

$this|string|null —

name()

name(string|null  $name = null) : $this|string|null

Alias for getName().

Parameters

string|null $name

Holds the route name.

Returns

$this|string|null —

matches()

matches(string  $method, string  $path) : bool

Checks if the route matches a given HTTP method and path.

Parameters

string $method

Holds the HTTP method to match.

string $path

Holds the path to match.

Returns

bool —

Returns true if the route matches, false otherwise.

dispatch()

dispatch() : mixed

Dispatches the route handler.

This method invokes the registered handler for the route, typically a controller action.

Returns

mixed —

The result of the route handler.

normalisePath()

normalisePath(string  $path) : string

Normalizes the path by removing leading and trailing slashes.

Parameters

string $path

Holds the path to normalize.

Returns

string —

Returns the normalized path.