Route
in package
implements
JsonSerializable
Class Route.
Interfaces, Classes, Traits and Enums
- JsonSerializable
Table of Contents
- $action : Closure|string
- $actionArguments : array<string|int, mixed>
- $name : string|null
- $options : array<string|int, mixed>
- $origin : string
- $path : string
- $router : Router
- __construct() : mixed
- Route constructor.
- getAction() : Closure|string
- Gets the Route action.
- getActionArguments() : array<int, string>
- Gets the Route action arguments.
- getName() : string|null
- Gets the Route name.
- getOptions() : array<string, mixed>
- Gets Route options.
- getOrigin() : string
- Gets the Route URL origin.
- getPath() : string
- Gets the Route URL path.
- getUrl() : string
- Gets the Route URL.
- jsonSerialize() : string
- run() : Response
- Runs the Route action.
- setAction() : static
- Sets the Route action.
- setActionArguments() : static
- Sets the Route action arguments.
- setName() : static
- Sets the Route name.
- setOptions() : static
- Sets options to be used in a specific environment application.
- setPath() : static
- Sets the Route URL path.
- extractMethodAndArguments() : array<int, mixed>
- makeResponse() : Response
- Make the final Response used in the 'run' method.
- makeResponseBodyPart() : string
- Make a string to be appended in the Response body based in the route action result.
- onNamedRoutePart() : string
- setOrigin() : static
- toArrayOfStrings() : array<int, string>
Properties
$action
protected
Closure|string
$action
$actionArguments
protected
array<string|int, mixed>
$actionArguments
= []
$name
protected
string|null
$name
= null
$options
protected
array<string|int, mixed>
$options
= []
$origin
protected
string
$origin
$path
protected
string
$path
$router
protected
Router
$router
Methods
__construct()
Route constructor.
public
__construct(Router $router, string $origin, string $path, Closure|string $action) : mixed
Parameters
- $router : Router
-
A Router instance
- $origin : string
-
URL Origin. A string in the following format: {scheme}://{hostname}[:{port}]
- $path : string
-
URL Path. A string starting with '/'
- $action : Closure|string
-
The action
Return values
mixed —getAction()
Gets the Route action.
public
getAction() : Closure|string
Return values
Closure|string —getActionArguments()
Gets the Route action arguments.
public
getActionArguments() : array<int, string>
Return values
array<int, string> —getName()
Gets the Route name.
public
getName() : string|null
Return values
string|null —getOptions()
Gets Route options.
public
getOptions() : array<string, mixed>
Return values
array<string, mixed> —getOrigin()
Gets the Route URL origin.
public
getOrigin(string ...$arguments) : string
Parameters
- $arguments : string
-
Arguments to fill the URL Origin placeholders
Return values
string —getPath()
Gets the Route URL path.
public
getPath(string ...$arguments) : string
Parameters
- $arguments : string
-
Arguments to fill the URL Path placeholders
Return values
string —getUrl()
Gets the Route URL.
public
getUrl([array<string|int, mixed> $originArgs = [] ][, array<string|int, mixed> $pathArgs = [] ]) : string
Note: Arguments must be passed if placeholders need to be filled.
Parameters
- $originArgs : array<string|int, mixed> = []
-
Arguments to fill the URL Origin placeholders
- $pathArgs : array<string|int, mixed> = []
-
Arguments to fill the URL Path placeholders
Return values
string —jsonSerialize()
public
jsonSerialize() : string
Return values
string —run()
Runs the Route action.
public
run(mixed ...$construct) : Response
Parameters
- $construct : mixed
-
Class constructor arguments
Tags
Return values
Response —The Response with the action result appended on the body
setAction()
Sets the Route action.
public
setAction(Closure|string $action) : static
Parameters
- $action : Closure|string
-
A Closure or a string in the format of the
__METHOD__
constant. Example:App\Blog::show
.The action can be suffixed with ordered parameters, separated by slashes, to set how the arguments will be passed to the class method. Example:
App\Blog::show/0/2/1
.And, also with the asterisk wildcard, to pass all arguments in the incoming order. Example:
App\Blog::show/*
Tags
Return values
static —setActionArguments()
Sets the Route action arguments.
public
setActionArguments(array<int, string> $arguments) : static
Parameters
- $arguments : array<int, string>
-
The arguments. Note that the indexes set the order of how the arguments are passed to the Action
Tags
Return values
static —setName()
Sets the Route name.
public
setName(string $name) : static
Parameters
- $name : string
Return values
static —setOptions()
Sets options to be used in a specific environment application.
public
setOptions(array<string, mixed> $options) : static
For example: its possible set Access Control List options, Locations, Middleware filters, etc.
Parameters
- $options : array<string, mixed>
Return values
static —setPath()
Sets the Route URL path.
public
setPath(string $path) : static
Parameters
- $path : string
Return values
static —extractMethodAndArguments()
protected
extractMethodAndArguments(string $part) : array<int, mixed>
Parameters
- $part : string
-
An action part like: index/0/2/1
Tags
Return values
array<int, mixed> —The action method in the first index, the action arguments in the second
makeResponse()
Make the final Response used in the 'run' method.
protected
makeResponse(mixed $result) : Response
Parameters
- $result : mixed
Tags
Return values
Response —makeResponseBodyPart()
Make a string to be appended in the Response body based in the route action result.
protected
makeResponseBodyPart(mixed $result) : string
Parameters
- $result : mixed
-
The return value of the matched route action
Tags
Return values
string —onNamedRoutePart()
protected
onNamedRoutePart() : string
Return values
string —setOrigin()
protected
setOrigin(string $origin) : static
Parameters
- $origin : string
Return values
static —toArrayOfStrings()
protected
static toArrayOfStrings(array<string|int, mixed> $array) : array<int, string>
Parameters
- $array : array<string|int, mixed>