Router
in package
implements
RouterInterface
Application Router
PHP Mini Framework
Tags
Interfaces, Classes, Traits and Enums
- RouterInterface
- PHP Mini Framework
Table of Contents
- ESCAPE_LIST = ["/" => "\\/", "." => "\\."]
- MATCHER_REGX = ["/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ALPHA . "\\)/" => "([a-zA-Z]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ALPHA_NUM . "\\)/" => "([a-zA-Z-_]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ALPHA_NUM_DASH . "\\)/" => "([a-zA-Z0-9-_]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::NUM . "\\)/" => "([0-9]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ANY . "\\)/" => "(.+)"]
- PARAM_NAME_REGX = ["/\\{\\w*\\}/" => "([a-zA-Z0-9-_]+)"]
- Use to match route path to an exact variable name. e.g $uid = /user/{uid}
- PATH_EXCLUDE_LIST = ["\$", "<", ">", "[", "]", "{", "}", "^", "\\", "|", "%"]
- $routes : array<string|int, RouteInterface>
- addRoute() : RouterInterface
- addRoutes() : RouterInterface
- createRoute() : RouteInterface
- getRoutes() : array<string|int, RouteInterface>
- isMatch() : bool|array<string|int, mixed>
- Check if path matches
- process() : array<string|int, MiddlewareInterface>
- Process routing
- createMatchParamsRoute() : string
- Create route to be used for params matching
Constants
ESCAPE_LIST
public
mixed
ESCAPE_LIST
= ["/" => "\\/", "." => "\\."]
Tags
MATCHER_REGX
public
mixed
MATCHER_REGX
= ["/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ALPHA . "\\)/" => "([a-zA-Z]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ALPHA_NUM . "\\)/" => "([a-zA-Z-_]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ALPHA_NUM_DASH . "\\)/" => "([a-zA-Z0-9-_]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::NUM . "\\)/" => "([0-9]+)", "/\\(" . \Busarm\PhpMini\Enums\RouteMatcher::ANY . "\\)/" => "(.+)"]
Tags
PARAM_NAME_REGX
Use to match route path to an exact variable name. e.g $uid = /user/{uid}
public
mixed
PARAM_NAME_REGX
= ["/\\{\\w*\\}/" => "([a-zA-Z0-9-_]+)"]
Tags
PATH_EXCLUDE_LIST
public
mixed
PATH_EXCLUDE_LIST
= ["\$", "<", ">", "[", "]", "{", "}", "^", "\\", "|", "%"]
Tags
Properties
$routes
protected
array<string|int, RouteInterface>
$routes
= []
HTTP routes
Tags
Methods
addRoute()
public
addRoute(RouteInterface $route) : RouterInterface
Parameters
- $route : RouteInterface
Tags
Return values
RouterInterface —addRoutes()
public
addRoutes(array<string|int, mixed> $routes) : RouterInterface
Parameters
- $routes : array<string|int, mixed>
Tags
Return values
RouterInterface —createRoute()
public
createRoute(string $method, string $path) : RouteInterface
Parameters
- $method : string
-
@see \Busarm\PhpMini\Enums\HttpMethod
- $path : string
Tags
Return values
RouteInterface —getRoutes()
public
getRoutes() : array<string|int, RouteInterface>
Tags
Return values
array<string|int, RouteInterface> —isMatch()
Check if path matches
public
isMatch(string $path, string $route[, bool $startsWith = true ][, mixed $endsWith = true ]) : bool|array<string|int, mixed>
Parameters
- $path : string
-
Request path
- $route : string
-
Route to compare to
- $startsWith : bool = true
-
path ends with route
- $endsWith : mixed = true
Tags
Return values
bool|array<string|int, mixed> —process()
Process routing
public
process([RequestInterface|RouteInterface|null $request = null ]) : array<string|int, MiddlewareInterface>
Parameters
- $request : RequestInterface|RouteInterface|null = null
Tags
Return values
array<string|int, MiddlewareInterface> —createMatchParamsRoute()
Create route to be used for params matching
protected
createMatchParamsRoute(string $route[, mixed &$paramMatches = [] ]) : string
Parameters
- $route : string
- $paramMatches : mixed = []
Tags
Return values
string —New route for regexp matching