Router
in package
Router class manages static calls to HTTP methods, parses the registered routes and parses the current requested URI.
Table of Contents
Properties
- $groupMiddlewares : array<string|int, mixed>|null
- $methods : 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.
- addRoute() : void|Router
- Registers a Route object.
- delete() : Route
- dispatch() : mixed
- Dispatches the content for the route (URI) and method (REQUEST_METHOD).
- get() : Route
- 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.
- 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
Properties
$groupMiddlewares
private
static array<string|int, mixed>|null
$groupMiddlewares
= null
$methods
private
static array<string|int, mixed>
$methods
= ['get', 'post', 'put', 'patch', 'delete']
$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
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
RoutegetRoutes()
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
match()
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>