Router
in package
Pop router class
Tags
Table of Contents
Properties
- $action : mixed
- Action
- $dispatchable : mixed
- Dispatchable object
- $dispatchableClass : string|null
- Dispatchable class
- $dispatchableTraitsCache : array<string, array<string|int, string>>
- Cache of resolved trait names (own + inherited) per dispatchable class name.
- $routeMatch : MatchInterface|null
- Route match object
Methods
- __call() : static
- Magic method to register a route for a whitelisted custom HTTP method
- __construct() : mixed
- Constructor
- acceptsHtml() : bool
- Determine if the inbound request has a real preference for an HTML response
- addCustomMethod() : static
- Add a custom HTTP method to the whitelist
- addCustomMethods() : static
- Add multiple custom HTTP methods to the whitelist
- addDispatchableParams() : static
- Add dispatchable params to be passed into a new dispatchable instance
- addRoute() : static
- Add a route
- addRoutes() : static
- Add multiple controller routes
- appendDispatchableParams() : static
- Append dispatchable params to be passed into a new dispatchable instance
- connect() : static
- Add a CONNECT route
- delete() : static
- Add a DELETE route
- get() : static
- Add a GET route
- getAction() : mixed
- Get the action
- getAllowedMethods() : array<string|int, mixed>
- Get the methods accepted by at least one path-matching route from the last route() call
- getDispatchable() : mixed
- Get the current dispatchable object
- getDispatchableClass() : string
- Get the current dispatchable class name
- getDispatchableParams() : mixed
- Get the params assigned to the dispatchable
- getRouteMatch() : MatchInterface
- Get route match object
- getRouteParams() : array<string|int, mixed>
- Get the params discovered from the route
- getRoutes() : array<string|int, mixed>
- Get routes
- getUrl() : string
- Get URL for the named route
- hasAction() : bool
- Determine if the router has an action
- hasCustomMethod() : bool
- Determine if a custom HTTP method has been whitelisted
- hasDispatchable() : bool
- Determine if the router has a dispatchable
- hasDispatchableParams() : bool
- Determine if the dispatchable has params
- hasMethodMismatch() : bool
- Determine if the last route() call matched a path whose method was rejected
- hasName() : bool
- Has a route name
- hasRoute() : bool
- Determine if there is a route match
- hasRouteParams() : bool
- Determine if the route has params
- head() : static
- Add a HEAD route
- isCli() : bool
- Determine if the route is CLI
- isHttp() : bool
- Determine if the route is HTTP
- methodNotAllowed() : void
- Send a 405 Method Not Allowed response
- name() : static
- Add a route name
- noRouteFound() : void
- Method to process if a route was not found
- options() : static
- Add an OPTIONS route
- patch() : static
- Add a PATCH route
- post() : static
- Add a POST route
- prepare() : static
- Prepare routes
- put() : static
- Add a PUT route
- removeDispatchableParams() : static
- Remove dispatchable params
- route() : void
- Route to the correct controller
- trace() : static
- Add a TRACE route
- httpMatch() : Http
- Get the active HTTP match object, guarding that the router is in HTTP mode
Properties
$action
Action
protected
mixed
$action
= null
$dispatchable
Dispatchable object
protected
mixed
$dispatchable
= null
$dispatchableClass
Dispatchable class
protected
string|null
$dispatchableClass
= null
$dispatchableTraitsCache
Cache of resolved trait names (own + inherited) per dispatchable class name.
protected
static array<string, array<string|int, string>>
$dispatchableTraitsCache
= []
A class's trait/inheritance shape never changes at runtime, so this is safe to share across all Router instances for the life of the process.
$routeMatch
Route match object
protected
MatchInterface|null
$routeMatch
= null
Methods
__call()
Magic method to register a route for a whitelisted custom HTTP method
public
__call(string $name, array<string|int, mixed> $arguments) : static
Only forwards to the HTTP match object when $name is either a real method there or a whitelisted custom verb - not in HTTP mode at all, or in HTTP mode but neither of those, both mean $name isn't a real method on Router, so it's reported as such rather than misdiagnosed as an HTTP/CLI mode mismatch or an unregistered custom HTTP verb (the explicit HTTP-only proxy methods like get()/post()/addCustomMethod() are unaffected - they call httpMatch() directly and still correctly throw "not HTTP" when called against a CLI-mode router).
Parameters
- $name : string
- $arguments : array<string|int, mixed>
Tags
Return values
static__construct()
Constructor
public
__construct([array<string|int, mixed>|null $routes = null ][, AbstractMatch|null $match = null ]) : mixed
Instantiate the router object
Parameters
- $routes : array<string|int, mixed>|null = null
- $match : AbstractMatch|null = null
acceptsHtml()
Determine if the inbound request has a real preference for an HTML response
public
acceptsHtml() : bool
Tags
Return values
booladdCustomMethod()
Add a custom HTTP method to the whitelist
public
addCustomMethod(string $method) : static
Parameters
- $method : string
Tags
Return values
staticaddCustomMethods()
Add multiple custom HTTP methods to the whitelist
public
addCustomMethods(array<string|int, mixed> $methods) : static
Parameters
- $methods : array<string|int, mixed>
Tags
Return values
staticaddDispatchableParams()
Add dispatchable params to be passed into a new dispatchable instance
public
addDispatchableParams(string $dispatchable, mixed $params) : static
Parameters
- $dispatchable : string
- $params : mixed
Return values
staticaddRoute()
Add a route
public
addRoute(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Return values
staticaddRoutes()
Add multiple controller routes
public
addRoutes(array<string|int, mixed> $routes) : static
Parameters
- $routes : array<string|int, mixed>
Return values
staticappendDispatchableParams()
Append dispatchable params to be passed into a new dispatchable instance
public
appendDispatchableParams(string $dispatchable, mixed $params) : static
Parameters
- $dispatchable : string
- $params : mixed
Return values
staticconnect()
Add a CONNECT route
public
connect(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticdelete()
Add a DELETE route
public
delete(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticget()
Add a GET route
public
get(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticgetAction()
Get the action
public
getAction() : mixed
getAllowedMethods()
Get the methods accepted by at least one path-matching route from the last route() call
public
getAllowedMethods() : array<string|int, mixed>
Return values
array<string|int, mixed>getDispatchable()
Get the current dispatchable object
public
getDispatchable() : mixed
getDispatchableClass()
Get the current dispatchable class name
public
getDispatchableClass() : string
Return values
stringgetDispatchableParams()
Get the params assigned to the dispatchable
public
getDispatchableParams(string $dispatchable) : mixed
Parameters
- $dispatchable : string
getRouteMatch()
Get route match object
public
getRouteMatch() : MatchInterface
Return values
MatchInterfacegetRouteParams()
Get the params discovered from the route
public
getRouteParams() : array<string|int, mixed>
Return values
array<string|int, mixed>getRoutes()
Get routes
public
getRoutes() : array<string|int, mixed>
Return values
array<string|int, mixed>getUrl()
Get URL for the named route
public
getUrl(string $routeName[, mixed $params = null ][, bool $fqdn = false ]) : string
Parameters
- $routeName : string
- $params : mixed = null
- $fqdn : bool = false
Tags
Return values
stringhasAction()
Determine if the router has an action
public
hasAction() : bool
Return values
boolhasCustomMethod()
Determine if a custom HTTP method has been whitelisted
public
hasCustomMethod(string $method) : bool
Parameters
- $method : string
Tags
Return values
boolhasDispatchable()
Determine if the router has a dispatchable
public
hasDispatchable() : bool
Return values
boolhasDispatchableParams()
Determine if the dispatchable has params
public
hasDispatchableParams(string $dispatchable) : bool
Parameters
- $dispatchable : string
Return values
boolhasMethodMismatch()
Determine if the last route() call matched a path whose method was rejected
public
hasMethodMismatch() : bool
Return values
boolhasName()
Has a route name
public
hasName(string $routeName) : bool
Parameters
- $routeName : string
Return values
boolhasRoute()
Determine if there is a route match
public
hasRoute() : bool
Return values
boolhasRouteParams()
Determine if the route has params
public
hasRouteParams() : bool
Return values
boolhead()
Add a HEAD route
public
head(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticisCli()
Determine if the route is CLI
public
isCli() : bool
Return values
boolisHttp()
Determine if the route is HTTP
public
isHttp() : bool
Tags
Return values
boolmethodNotAllowed()
Send a 405 Method Not Allowed response
public
methodNotAllowed(array<string|int, mixed> $allowedMethods[, bool $exit = true ]) : void
Parameters
- $allowedMethods : array<string|int, mixed>
- $exit : bool = true
Tags
name()
Add a route name
public
name(string $routeName) : static
Parameters
- $routeName : string
Return values
staticnoRouteFound()
Method to process if a route was not found
public
noRouteFound([bool $exit = true ]) : void
Parameters
- $exit : bool = true
options()
Add an OPTIONS route
public
options(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticpatch()
Add a PATCH route
public
patch(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticpost()
Add a POST route
public
post(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticprepare()
Prepare routes
public
prepare() : static
Return values
staticput()
Add a PUT route
public
put(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
staticremoveDispatchableParams()
Remove dispatchable params
public
removeDispatchableParams(string $dispatchable) : static
Parameters
- $dispatchable : string
Return values
staticroute()
Route to the correct controller
public
route([string|array<string|int, mixed>|null $forceRoute = null ]) : void
Parameters
- $forceRoute : string|array<string|int, mixed>|null = null
Tags
trace()
Add a TRACE route
public
trace(string $route, mixed $controller) : static
Parameters
- $route : string
- $controller : mixed
Tags
Return values
statichttpMatch()
Get the active HTTP match object, guarding that the router is in HTTP mode
protected
httpMatch() : Http