Route

This is a single entity for a Route.

The architecture is highly inspired by the Symfony Routing Component.

Table of Contents

Properties

$methods  : array<string|int, mixed>
$options  : array<string|int, mixed>
$path  : string

Methods

__construct()  : mixed
Constructor setting up the required path and options
getMethods()  : array<string|int, string>
Returns the uppercased HTTP methods this route is restricted to.
getOption()  : mixed
Get an option value
getOptions()  : array<string|int, mixed>
Returns the options set
getPath()  : string
Returns the path
hasOption()  : bool
Checks if an option has been set
setMethods()  : self
Sets the HTTP methods (e.g. ['POST']) this route is restricted to.
setOption()  : Route
Sets an option value
setOptions()  : Route
Sets the options
setPath()  : Route
Sets the pattern for the path A pattern must start with a slash and must not have multiple slashes at the beginning because the generated path for this route would be confused with a network path, e.g. '//domain.com/path'.

Properties

$methods

protected array<string|int, mixed> $methods = []

$options

protected array<string|int, mixed> $options = []

Methods

__construct()

Constructor setting up the required path and options

public __construct(string $path, array<string|int, mixed> $options) : mixed
Parameters
$path : string

The path pattern to match

$options : array<string|int, mixed>

An array of options

getMethods()

Returns the uppercased HTTP methods this route is restricted to.

public getMethods() : array<string|int, string>

An empty array means that any method is allowed.

Return values
array<string|int, string>

The methods

getOption()

Get an option value

public getOption(string $name) : mixed
Parameters
$name : string

An option name

Return values
mixed

The option value or NULL when not given

getOptions()

Returns the options set

public getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>

The options

getPath()

Returns the path

public getPath() : string
Return values
string

The path pattern

hasOption()

Checks if an option has been set

public hasOption(string $name) : bool
Parameters
$name : string

An option name

Return values
bool

TRUE if the option is set, FALSE otherwise

setMethods()

Sets the HTTP methods (e.g. ['POST']) this route is restricted to.

public setMethods(array<string|int, string> $methods) : self

An empty array means that any method is allowed.

This method implements a fluent interface.

Parameters
$methods : array<string|int, string>

The array of allowed methods

Return values
self

setOption()

Sets an option value

public setOption(string $name, mixed $value) : Route

This method implements a fluent interface.

Parameters
$name : string

An option name

$value : mixed

The option value

Return values
Route

The current Route instance

setOptions()

Sets the options

public setOptions(array<string|int, mixed> $options) : Route

This method implements a fluent interface.

Parameters
$options : array<string|int, mixed>

The options

Return values
Route

The current Route instance

setPath()

Sets the pattern for the path A pattern must start with a slash and must not have multiple slashes at the beginning because the generated path for this route would be confused with a network path, e.g. '//domain.com/path'.

public setPath(string $pattern) : Route

This method implements a fluent interface.

Parameters
$pattern : string

The path pattern

Return values
Route

The current Route instance


        
On this page

Search results