Route
extends Router
in package
Router class manages static calls to HTTP methods, parses the registered routes and parses the current requested URI.
Table of Contents
Constants
Properties
- $handler : string|callable
- $params : array<string|int, mixed>
- $path : string
- $subdomain : string
- $uriParts : array<string|int, mixed>
- $content : string
- $groupMiddlewares : array<string|int, mixed>|null
- $methods : array<string|int, mixed>
- $middlewares : array<string|int, mixed>
- $routes : array<string|int, mixed>
Methods
- __callStatic() : void
- Registers a new Route based on the static call of the requested method.
- __construct() : mixed
- Constructor
- addRoute() : void|Router
- Registers a Route object.
- delete() : Route
- dispatch() : mixed
- Dispatches the content for the route (URI) and method (REQUEST_METHOD).
- get() : Route
- getContent() : void
- Returns the already processed content that corresponds to the request.
- getMiddlewares() : array<string|int, mixed>
- Returns registered middlewares.
- getRoutes() : array<string|int, mixed>
- Returns current registered routes from Router.
- getUriParts() : array<string|int, mixed>
- Parses a URI and return its parts and the subdomain if there is any.
- group() : void
- Groups routes to run a list of middlewares on them.
- handler() : Route
- Determines the type of handler should be called: closure|callable or Controller
- isMiddleware() : bool
- Checks if $middleware is a valid Middleware class
- match() : bool|Route
- Confirms if the URI and the REQUEST_METHOD matches any registred route.
- parseRoute() : void
- Destructs a route. It returns the URI parts and the subdomain if there is any.
- path() : Route
- post() : Route
- put() : Route
- runMiddlewares() : void
- Runs statically middlewares
- withMiddleware() : Route
- Registers one or multiple middlewares sequentially.
- callController() : void
- Makes the controller call and assign the controller result to the content property.
Constants
DELETE
public
string
DELETE
= 'delete'
GET
public
string
GET
= 'get'
PATCH
public
string
PATCH
= 'patch'
POST
public
string
POST
= 'post'
PUT
public
string
PUT
= 'put'
Properties
$handler
public
string|callable
$handler
= null
$params
public
array<string|int, mixed>
$params
= []
$path
public
string
$path
$subdomain
public
string
$subdomain
= null
$uriParts
public
array<string|int, mixed>
$uriParts
= []
$content
protected
string
$content
= null
$groupMiddlewares
private
static array<string|int, mixed>|null
$groupMiddlewares
= null
$methods
private
static array<string|int, mixed>
$methods
= ['get', 'post', 'put', 'patch', 'delete']
$middlewares
private
array<string|int, mixed>
$middlewares
= []
$routes
private
array<string|int, mixed>
$routes
= []
Methods
__callStatic()
Registers a new Route based on the static call of the requested method.
public
static __callStatic(string $requestedMethod, array<string|int, mixed> $args) : void
Parameters
- $requestedMethod : string
- $args : array<string|int, mixed>
Tags
__construct()
Constructor
public
__construct(string $path[, string|callable $handler = null ]) : mixed
Parameters
- $path : string
- $handler : string|callable = null
addRoute()
Registers a Route object.
public
addRoute(string $method, Route $route) : void|Router
Parameters
- $method : string
- $route : Route
Return values
void|Routerdelete()
public
static delete(string $route, callable|string $handler) : Route
Parameters
- $route : string
- $handler : callable|string
Return values
Routedispatch()
Dispatches the content for the route (URI) and method (REQUEST_METHOD).
public
dispatch() : mixed
Tags
get()
public
static get(string $route, callable|string $handler) : Route
Parameters
- $route : string
- $handler : callable|string
Return values
RoutegetContent()
Returns the already processed content that corresponds to the request.
public
getContent() : void
getMiddlewares()
Returns registered middlewares.
public
getMiddlewares() : array<string|int, mixed>
Return values
array<string|int, mixed>getRoutes()
Returns current registered routes from Router.
public
getRoutes([string $method = '' ][, string $subdomain = '*' ]) : array<string|int, mixed>
Parameters
- $method : string = ''
- $subdomain : string = '*'
Return values
array<string|int, mixed>getUriParts()
Parses a URI and return its parts and the subdomain if there is any.
public
getUriParts(string $uri) : array<string|int, mixed>
Parameters
- $uri : string
Return values
array<string|int, mixed>group()
Groups routes to run a list of middlewares on them.
public
static group(string|array<string|int, mixed> $middlewares, callable $callback) : void
Parameters
- $middlewares : string|array<string|int, mixed>
- $callback : callable
handler()
Determines the type of handler should be called: closure|callable or Controller
public
handler() : Route
Return values
RouteisMiddleware()
Checks if $middleware is a valid Middleware class
public
isMiddleware(string $middleware) : bool
Parameters
- $middleware : string
Return values
boolmatch()
Confirms if the URI and the REQUEST_METHOD matches any registred route.
public
match(string $method, string $uri) : bool|Route
Parameters
- $method : string
- $uri : string
Return values
bool|RouteparseRoute()
Destructs a route. It returns the URI parts and the subdomain if there is any.
public
parseRoute(Route $route) : void
Subdomain will be appended with '@'. : admin.domain.com/login will be [admin@, loging]
Parameters
- $route : Route
path()
public
static path(string $route, callable|string $handler) : Route
Parameters
- $route : string
- $handler : callable|string
Return values
Routepost()
public
static post(string $route, callable|string $handler) : Route
Parameters
- $route : string
- $handler : callable|string
Return values
Routeput()
public
static put(string $route, callable|string $handler) : Route
Parameters
- $route : string
- $handler : callable|string
Return values
RouterunMiddlewares()
Runs statically middlewares
public
static runMiddlewares(array<string|int, mixed> $middlewares) : void
Parameters
- $middlewares : array<string|int, mixed>
withMiddleware()
Registers one or multiple middlewares sequentially.
public
withMiddleware(string|array<string|int, mixed> $middlewares) : Route
Parameters
- $middlewares : string|array<string|int, mixed>
Return values
RoutecallController()
Makes the controller call and assign the controller result to the content property.
private
callController(string $controller) : void
Parameters
- $controller : string