Documentation

SimpleRouter extends RouterBase
in package
implements RouterInterface Uses SimpleRoutesSet, SimpleUrlParser

Simple 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
dumpOnDisk()  : void
Method dumps all routes and their names on disk
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
loadFromDisk()  : void
Method loads routes from disk
noProcessorFoundErrorHandler()  : void
Method processes no processor found error
registerMiddleware()  : void
Method registeres middleware for the router
setNoProcessorFoundErrorHandler()  : callable|null
Method sets InvalidRouteErrorHandler function
addParamRoute()  : void
Method adds param router
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
paramRouteExists()  : bool
Method returns true if the param router exists
setCalledRoute()  : void
Method sets $calledRoute
setParameters()  : void
Method sets parameters
_getParameterNames()  : array<string|int, string>
Method returns all parameter names in the route
_getRouteMatcherRegExPattern()  : string
Method compiles route pattern string in regex string.
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
see
RouterInterface::callRoute()
psalm-suppress

MixedAssignment

Return values
mixed

value returned by route handler

dumpOnDisk()

Method dumps all routes and their names on disk

public dumpOnDisk([string $filePath = './cache/cache.php' ]) : void
Parameters
$filePath : string = './cache/cache.php'

file path to cache

Tags
codeCoverageIgnore
Return values
void

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
psalm-suppress

MixedReturnStatement

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

loadFromDisk()

Method loads routes from disk

public loadFromDisk([string $filePath = './cache/cache.php' ]) : void
Parameters
$filePath : string = './cache/cache.php'

file path to cache

Tags
codeCoverageIgnore
psalm-suppress

UnresolvableInclude, MixedArrayAccess, MixedAssignment

Return values
void

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

addParamRoute()

Method adds param router

protected addParamRoute(string $requestMethod, string $route, mixed $callback) : void
Parameters
$requestMethod : string

request method

$route : string

route

$callback : mixed
Return values
void

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
psalm-param

callable|string|array{0: string, 1: string} $processor

Return values
mixed

route handler execution result

getAllRoutesTrace()

Method rturns all available routes

protected abstract getAllRoutesTrace() : string
Tags
psalm-suppress

PossiblyUndefinedArrayOffset

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

paramRouteExists()

Method returns true if the param router exists

protected paramRouteExists(string $route, string $requestMethod) : bool
Parameters
$route : string

checking route

$requestMethod : string

HTTP request method

Tags
psalm-suppress

PossiblyUndefinedArrayOffset

Return values
bool

true if the param router exists, false otherwise

setCalledRoute()

Method sets $calledRoute

protected abstract 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

_getParameterNames()

Method returns all parameter names in the route

private _getParameterNames(string $routerPattern) : array<string|int, string>
Parameters
$routerPattern : string

route

Return values
array<string|int, string>

names

_getRouteMatcherRegExPattern()

Method compiles route pattern string in regex string.

private _getRouteMatcherRegExPattern(string $routerPattern) : string

For example [i:id]/some-str in ([[0-9]])/some-str

Parameters
$routerPattern : string

router pattern

Return values
string

regexp pattern

initDefaultTypes()

Init types

private initDefaultTypes() : void
Return values
void

Search results

    Яндекс.Метрика