RouteCollection
in package
implements
Countable, JsonSerializable
Class RouteCollection.
Interfaces, Classes, Traits and Enums
- Countable
- JsonSerializable
Table of Contents
- $name : string|null
- $origin : string
- $router : Router
- $routes : array<string, array<string|int, Route>>
- $name : string|null
- $notFoundAction : Closure|string
- The Error 404 page action.
- $origin : string
- $router : Router
- $routes : array<string|int, mixed>
- Array of HTTP Methods as keys and array of Routes as values.
- __call() : Route|null
- __construct() : mixed
- RouteCollection constructor.
- __get() : mixed
- __isset() : bool
- add() : Route
- Adds a Route to match many HTTP Methods.
- count() : int
- Count routes in the collection.
- delete() : Route
- Adds a Route to match the HTTP DELETE Method.
- get() : Route
- Adds a Route to match the HTTP GET Method.
- group() : array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]>
- Groups many Routes into a URL path.
- jsonSerialize() : array<string, mixed>
- namespace() : array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]>
- Updates Routes actions, which are strings, prepending a namespace.
- notFound() : void
- Sets the Route Not Found action for this collection.
- options() : Route
- Adds a Route to match the HTTP OPTIONS Method.
- patch() : Route
- Adds a Route to match the HTTP PATCH Method.
- post() : Route
- Adds a Route to match the HTTP POST Method.
- presenter() : array<int, Route>
- Adds many Routes that can be used by a User Interface.
- put() : Route
- Adds a Route to match the HTTP PUT Method.
- redirect() : Route
- Adds a GET Route to match a path and automatically redirects to a URL.
- resource() : array<int, Route>
- Adds many Routes that can be used as a REST Resource.
- addRoute() : static
- addSimple() : Route
- getRouteName() : string
- Get a Route name.
- getRouteNotFound() : Route|null
- Gets the Route Not Found for this collection.
- makeRoute() : Route
- makeRouteActionFromArray() : string
- setOrigin() : static
Properties
$name read-only
public
string|null
$name
$origin read-only
public
string
$origin
$router read-only
public
Router
$router
$routes read-only
public
array<string, array<string|int, Route>>
$routes
$name
protected
string|null
$name
$notFoundAction
The Error 404 page action.
protected
Closure|string
$notFoundAction
$origin
protected
string
$origin
$router
protected
Router
$router
$routes
Array of HTTP Methods as keys and array of Routes as values.
protected
array<string|int, mixed>
$routes
= []
Methods
__call()
public
__call(string $method, array<int, mixed> $arguments) : Route|null
Parameters
- $method : string
- $arguments : array<int, mixed>
Tags
Return values
Route|null —__construct()
RouteCollection constructor.
public
__construct(Router $router, string $origin[, string|null $name = null ]) : mixed
Parameters
- $router : Router
-
A Router instance
- $origin : string
-
URL Origin. A string in the following format:
{scheme}://{hostname}[:{port}]
- $name : string|null = null
-
The collection name
Return values
mixed —__get()
public
__get(string $property) : mixed
Parameters
- $property : string
Tags
Return values
mixed —__isset()
public
__isset(string $property) : bool
Parameters
- $property : string
Return values
bool —add()
Adds a Route to match many HTTP Methods.
public
add(array<int, string> $httpMethods, string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $httpMethods : array<int, string>
-
The HTTP Methods
- $path : string
-
The URL path
- $action : Closure|array<int, string>|string
-
The Route action
- $name : string|null = null
-
The Route name
Tags
Return values
Route —count()
Count routes in the collection.
public
count() : int
Return values
int —delete()
Adds a Route to match the HTTP DELETE Method.
public
delete(string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $path : string
-
The URL path
- $action : Closure|array<int, string>|string
-
The Route action
- $name : string|null = null
-
The Route name
Tags
Return values
Route —The Route added to the collection
get()
Adds a Route to match the HTTP GET Method.
public
get(string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $path : string
-
The URL path
- $action : Closure|array<int, string>|string
-
The Route action
- $name : string|null = null
-
The Route name
Tags
Return values
Route —The Route added to the collection
group()
Groups many Routes into a URL path.
public
group(string $basePath, array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]> $routes[, array<string, mixed> $options = [] ]) : array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]>
Parameters
- $basePath : string
-
The URL path to group in
- $routes : array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]>
-
The Routes to be grouped
- $options : array<string, mixed> = []
-
Custom options passed to the Routes
Return values
array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]> —The same $routes with updated paths and options
jsonSerialize()
public
jsonSerialize() : array<string, mixed>
Return values
array<string, mixed> —namespace()
Updates Routes actions, which are strings, prepending a namespace.
public
namespace(string $namespace, array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]> $routes) : array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]>
Parameters
- $namespace : string
-
The namespace
- $routes : array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]>
-
The Routes
Return values
array<string|int, \Framework\Routing\Route|(\Framework\Routing\Route|mixed)[]> —The same $routes with updated actions
notFound()
Sets the Route Not Found action for this collection.
public
notFound(Closure|string $action) : void
Parameters
- $action : Closure|string
-
the Route function to run when no Route path is found for this collection
Return values
void —options()
Adds a Route to match the HTTP OPTIONS Method.
public
options(string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $path : string
-
The URL path
- $action : Closure|array<int, string>|string
-
The Route action
- $name : string|null = null
-
The Route name
Tags
Return values
Route —The Route added to the collection
patch()
Adds a Route to match the HTTP PATCH Method.
public
patch(string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $path : string
-
The URL path
- $action : Closure|array<int, string>|string
-
The Route action
- $name : string|null = null
-
The Route name
Tags
Return values
Route —The Route added to the collection
post()
Adds a Route to match the HTTP POST Method.
public
post(string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $path : string
-
The URL path
- $action : Closure|array<int, string>|string
-
The Route action
- $name : string|null = null
-
The Route name
Tags
Return values
Route —The Route added to the collection
presenter()
Adds many Routes that can be used by a User Interface.
public
presenter(string $path, string $class, string $baseName[, array<int, string> $except = [] ][, string $placeholder = '{int}' ]) : array<int, Route>
Parameters
- $path : string
-
The URL path
- $class : string
-
The name of the class where the resource will point
- $baseName : string
-
The base name used as a Route name prefix
- $except : array<int, string> = []
-
Actions not added. Allowed values are: index, new, create, show, edit, update, remove and delete
- $placeholder : string = '{int}'
-
The placeholder. Normally it matches an id, a number
Tags
Return values
array<int, Route> —The Routes added to the collection
put()
Adds a Route to match the HTTP PUT Method.
public
put(string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $path : string
-
The URL path
- $action : Closure|array<int, string>|string
-
The Route action
- $name : string|null = null
-
The Route name
Tags
Return values
Route —The Route added to the collection
redirect()
Adds a GET Route to match a path and automatically redirects to a URL.
public
redirect(string $path, string $location[, int $code = Status::TEMPORARY_REDIRECT ][, string|null $name = null ]) : Route
Parameters
- $path : string
-
The URL path
- $location : string
-
The URL to redirect
- $code : int = Status::TEMPORARY_REDIRECT
-
The status code of the response
- $name : string|null = null
-
The Route name
Return values
Route —The Route added to the collection
resource()
Adds many Routes that can be used as a REST Resource.
public
resource(string $path, string $class, string $baseName[, array<int, string> $except = [] ][, string $placeholder = '{int}' ]) : array<int, Route>
Parameters
- $path : string
-
The URL path
- $class : string
-
The name of the class where the resource will point
- $baseName : string
-
The base name used as a Route name prefix
- $except : array<int, string> = []
-
Actions not added. Allowed values are: index, create, show, update, replace and delete
- $placeholder : string = '{int}'
-
The placeholder. Normally it matches an id, a number
Tags
Return values
array<int, Route> —The Routes added to the collection
addRoute()
protected
addRoute(string $httpMethod, Route $route) : static
Parameters
- $httpMethod : string
- $route : Route
Tags
Return values
static —addSimple()
protected
addSimple(string $method, string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $method : string
- $path : string
- $action : Closure|array<int, string>|string
- $name : string|null = null
Return values
Route —getRouteName()
Get a Route name.
protected
getRouteName(string $name) : string
Parameters
- $name : string
-
The current Route name
Return values
string —The Route name prefixed with the collection name and a dot if it is set
getRouteNotFound()
Gets the Route Not Found for this collection.
protected
getRouteNotFound() : Route|null
Tags
Return values
Route|null —The Route containing the Not Found Action or null if the Action was not set
makeRoute()
protected
makeRoute(string $path, Closure|array<int, string>|string $action[, string|null $name = null ]) : Route
Parameters
- $path : string
- $action : Closure|array<int, string>|string
- $name : string|null = null
Return values
Route —makeRouteActionFromArray()
protected
makeRouteActionFromArray(array<int, string> $action) : string
Parameters
- $action : array<int, string>
Return values
string —setOrigin()
protected
setOrigin(string $origin) : static
Parameters
- $origin : string