RouterBase
in package
implements
RouterInterface
Uses
RouteTypes, InvalidRouteErrorHandler, StaticRoutes
Base router class
Interfaces, Classes and Traits
- RouterInterface
- Router interface
Table of Contents
- $middleware : array<string, array<string|int, callable>>
- Middleware for routes processing
- $staticRoutes : mixed
- List of static routes for all supported request methods
- $types : array<string, string>
- Supported types of URL parameters
- $calledRoute : string
- Called route
- $invalidRouteErrorHandler : callable|null
- Method wich handles invalid route error
- __construct() : mixed
- Constructor
- addType() : void
- Method adds custom type
- callRoute() : mixed
- Processing specified router
- fetchActions() : void
- Method fetches actions from the objects and creates GetRoutes for them
- getCallback() : mixed
- Method returns call back by it's router
- getCalledRoute() : string
- Method returns called route
- getNoProcessorErrorHandler() : callable
- Method returns error handler
- noProcessorFoundErrorHandler() : void
- Method processes no processor found error
- registerMiddleware() : void
- Method registeres middleware for the router
- setNoProcessorFoundErrorHandler() : callable|null
- Method sets InvalidRouteErrorHandler function
- clearMiddleware() : void
- Method clears middleware
- executeHandler() : mixed
- Method executes route handler
- getAllRoutesTrace() : string
- Method rturns all available routes
- getDynamicRouteProcessor() : mixed
- Method searches dynamic route processor
- getMiddlewareResult() : array<string|int, mixed>
- Method returns middleware processing result
- getParameters() : array<string|int, mixed>
- Method returns parameters
- getRequestMethod() : string
- Method returns request method
- getStaticRouteProcessor() : mixed
- Method returns route handler
- getStaticRoutes() : array<string|int, mixed>
- Method returns static routes handlers for the specified request methods
- getUniversalRouteProcessor() : mixed
- Method returns route handler
- setCalledRoute() : void
- Method sets $calledRoute
- setParameters() : void
- Method sets parameters
- initDefaultTypes() : void
- Init types
Properties
$middleware
Middleware for routes processing
protected
array<string, array<string|int, callable>>
$middleware
= []
$staticRoutes
List of static routes for all supported request methods
protected
mixed
$staticRoutes
= ['GET' => [], 'POST' => [], 'PUT' => [], 'DELETE' => [], 'OPTION' => [], 'PATCH' => []]
$types
Supported types of URL parameters
protected
array<string, string>
$types
= []
$calledRoute
Called route
private
string
$calledRoute
= ''
$invalidRouteErrorHandler
Method wich handles invalid route error
private
callable|null
$invalidRouteErrorHandler
= null
Methods
__construct()
Constructor
public
__construct() : mixed
Return values
mixed —addType()
Method adds custom type
public
addType(string $typeName, string $className) : void
Parameters
- $typeName : string
-
type name
- $className : string
-
name of the class wich represents custom type
Return values
void —callRoute()
Processing specified router
public
callRoute(mixed $route) : mixed
Parameters
- $route : mixed
-
route
Tags
Return values
mixed —value returned by route handler
fetchActions()
Method fetches actions from the objects and creates GetRoutes for them
public
fetchActions(object $object[, array<string|int, mixed> $map = [] ]) : void
Parameters
- $object : object
-
object to be processed
- $map : array<string|int, mixed> = []
-
map
Return values
void —getCallback()
Method returns call back by it's router
public
getCallback(array<string|int, string>|string $route) : mixed
Parameters
- $route : array<string|int, string>|string
-
route
Tags
Return values
mixed —getCalledRoute()
Method returns called route
public
getCalledRoute() : string
Return values
string —called route
getNoProcessorErrorHandler()
Method returns error handler
public
getNoProcessorErrorHandler() : callable
Return values
callable —noProcessorFoundErrorHandler()
Method processes no processor found error
public
noProcessorFoundErrorHandler(string $route) : void
Parameters
- $route : string
-
route
Return values
void —registerMiddleware()
Method registeres middleware for the router
public
registerMiddleware(string $router, callable $middleware) : void
Parameters
- $router : string
- $middleware : callable
-
middleware
Return values
void —setNoProcessorFoundErrorHandler()
Method sets InvalidRouteErrorHandler function
public
setNoProcessorFoundErrorHandler(callable $function) : callable|null
Parameters
- $function : callable
-
error handler
Return values
callable|null —old error handler
clearMiddleware()
Method clears middleware
protected
clearMiddleware() : void
Return values
void —executeHandler()
Method executes route handler
protected
abstract executeHandler(mixed $processor, string $route) : mixed
Parameters
- $processor : mixed
- $route : string
-
route
Tags
Return values
mixed —route handler execution result
getAllRoutesTrace()
Method rturns all available routes
protected
abstract getAllRoutesTrace() : string
Tags
Return values
string —trace
getDynamicRouteProcessor()
Method searches dynamic route processor
protected
abstract getDynamicRouteProcessor(string $route[, string $requestMethod = '' ]) : mixed
Parameters
- $route : string
-
route
- $requestMethod : string = ''
-
request method
Return values
mixed —getMiddlewareResult()
Method returns middleware processing result
protected
getMiddlewareResult(string $route) : array<string|int, mixed>
Parameters
- $route : string
-
processed route
Return values
array<string|int, mixed> —middleware result
getParameters()
Method returns parameters
protected
abstract getParameters() : array<string|int, mixed>
Return values
array<string|int, mixed> —getRequestMethod()
Method returns request method
protected
getRequestMethod() : string
Return values
string —request method
getStaticRouteProcessor()
Method returns route handler
protected
getStaticRouteProcessor(string $route) : mixed
Parameters
- $route : string
-
routes
Return values
mixed —getStaticRoutes()
Method returns static routes handlers for the specified request methods
protected
getStaticRoutes(string $requestMethod) : array<string|int, mixed>
Parameters
- $requestMethod : string
-
request method
Return values
array<string|int, mixed> —getUniversalRouteProcessor()
Method returns route handler
protected
getUniversalRouteProcessor() : mixed
Return values
mixed —setCalledRoute()
Method sets $calledRoute
protected
setCalledRoute(string $calledRoute) : void
Parameters
- $calledRoute : string
-
called router
Return values
void —setParameters()
Method sets parameters
protected
abstract setParameters(array<string|int, mixed> $parameters) : void
Parameters
- $parameters : array<string|int, mixed>
-
parameters
Return values
void —initDefaultTypes()
Init types
private
initDefaultTypes() : void