HttpRouter
in package
implements
IRouter
Uses
RouterTrait
Table of Contents
Interfaces
Methods
- __construct() : mixed
- add() : void
- Adds a new route.
- delete() : void
- dispatch() : void
- get() : void
- getCharSet() : string
- getErrorHandler() : IErrorHandler
- options() : void
- output() : void
- patch() : void
- post() : void
- put() : void
- register() : void
- registerContentHandler() : void
- registerDefaultContentHandlers() : void
- resolve() : ResolvedRouteInfo
- Resolves a route
- scopeTo() : IRouter
- Creates a scoped version of this router.
- setErrorHandler() : void
- setHTMLErrorHandler() : void
- setPlainErrorHandler() : void
- use() : void
- Apply middleware functions to a path.
- writeErrorPage() : void
Methods
__construct()
public
__construct([string $charSet = '' ][, IErrorHandler|string $errorHandler = 'html' ][, bool $registerDefaultContentHandlers = true ]) : mixed
Parameters
- $charSet : string = ''
- $errorHandler : IErrorHandler|string = 'html'
- $registerDefaultContentHandlers : bool = true
add()
Adds a new route.
public
add(string $method, string $path, callable $handler) : void
Parameters
- $method : string
-
Request method.
- $path : string
-
Request path.
- $handler : callable
-
Request handler.
delete()
public
delete(string $path, callable $handler) : void
Parameters
- $path : string
- $handler : callable
dispatch()
public
dispatch([HttpRequest|null $request = null ][, array<string|int, mixed> $args = [] ]) : void
Parameters
- $request : HttpRequest|null = null
- $args : array<string|int, mixed> = []
get()
public
get(string $path, callable $handler) : void
Parameters
- $path : string
- $handler : callable
getCharSet()
public
getCharSet() : string
Return values
stringgetErrorHandler()
public
getErrorHandler() : IErrorHandler
Return values
IErrorHandleroptions()
public
options(string $path, callable $handler) : void
Parameters
- $path : string
- $handler : callable
output()
public
static output(HttpResponse $response, bool $includeBody) : void
Parameters
- $response : HttpResponse
- $includeBody : bool
patch()
public
patch(string $path, callable $handler) : void
Parameters
- $path : string
- $handler : callable
post()
public
post(string $path, callable $handler) : void
Parameters
- $path : string
- $handler : callable
put()
public
put(string $path, callable $handler) : void
Parameters
- $path : string
- $handler : callable
register()
public
register(IRouteHandler $handler) : void
Parameters
- $handler : IRouteHandler
registerContentHandler()
public
registerContentHandler(IContentHandler $contentHandler) : void
Parameters
- $contentHandler : IContentHandler
registerDefaultContentHandlers()
public
registerDefaultContentHandlers() : void
resolve()
Resolves a route
public
resolve(string $method, string $path) : ResolvedRouteInfo
Parameters
- $method : string
-
Request method.
- $path : string
-
Request path.
Return values
ResolvedRouteInfo —Response route.
scopeTo()
Creates a scoped version of this router.
public
scopeTo(string $prefix) : IRouter
Parameters
- $prefix : string
-
Prefix path to prepend to all registered routes.
Return values
IRouter —Scoped router.
setErrorHandler()
public
setErrorHandler(IErrorHandler|string $handler) : void
Parameters
- $handler : IErrorHandler|string
setHTMLErrorHandler()
public
setHTMLErrorHandler() : void
setPlainErrorHandler()
public
setPlainErrorHandler() : void
use()
Apply middleware functions to a path.
public
use(string $path, callable $handler) : void
Parameters
- $path : string
-
Path to apply the middleware to.
- $handler : callable
-
Middleware function.
writeErrorPage()
public
writeErrorPage(HttpResponseBuilder $response, HttpRequest $request, int $statusCode) : void
Parameters
- $response : HttpResponseBuilder
- $request : HttpRequest
- $statusCode : int