Router
- Full name:
\Qubus\Routing\Router
- This class implements:
\Qubus\Routing\Psr7Router
,\Qubus\Routing\Interfaces\Mappable
,\Psr\Http\Server\MiddlewareInterface
Properties
request
version
routes
routeCollector
routesCreated
routeCollectorMatchTypeId
basePath
currentRoute
container
responseFactory
middlewareResolver
invoker
baseMiddleware
defaultNamespace
namespace
bootManagers
eventHandlers
Methods
__construct
public __construct(\Qubus\Routing\Interfaces\Collector $routeCollector, \Psr\Container\ContainerInterface $container, ?\Psr\Http\Message\ResponseFactoryInterface $responseFactory = null, ?\Qubus\Routing\Interfaces\MiddlewareResolver $resolver = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$routeCollector | \Qubus\Routing\Interfaces\Collector | |
$container | \Psr\Container\ContainerInterface | |
$responseFactory | ?\Psr\Http\Message\ResponseFactoryInterface | |
$resolver | ?\Qubus\Routing\Interfaces\MiddlewareResolver |
prependUrl
Parameters:
Parameter | Type | Description |
---|---|---|
$url | string |
setContainer
Set a container.
Parameters:
Parameter | Type | Description |
---|---|---|
$container | \Psr\Container\ContainerInterface |
setBasePath
Set the basepath.
Parameters:
Parameter | Type | Description |
---|---|---|
$basePath | string |
setDefaultNamespace
Set the default namespace for controllers.
Parameters:
Parameter | Type | Description |
---|---|---|
$namespace | string |
addRoute
Add route.
Parameters:
Parameter | Type | Description |
---|---|---|
$route | \Qubus\Routing\Route\Route | The route. |
Return Value:
Add route to routes array.
Throws:
convertRouteToRouteCollectorRouterUri
protected convertRouteToRouteCollectorRouterUri(\Qubus\Routing\Interfaces\Routable $route, \Qubus\Routing\Route\RouteCollector $routeCollector): string
Parameters:
Parameter | Type | Description |
---|---|---|
$route | \Qubus\Routing\Interfaces\Routable | |
$routeCollector | \Qubus\Routing\Route\RouteCollector |
map
Add a route to the map
Parameters:
Parameter | Type | Description |
---|---|---|
$verbs | array | HTTP methods. |
$uri | string | Route path. |
$callback | callable|string |
Throws:
resources
Register an array of resource controllers.
Parameters:
Parameter | Type | Description |
---|---|---|
$resources | array | |
$options | array |
resource
Route a resource to a controller.
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | |
$controller | string | |
$options | array |
apiResources
Register an array of API resource controllers.
Parameters:
Parameter | Type | Description |
---|---|---|
$resources | array | |
$options | array |
apiResource
Route an API resource to a controller.
public apiResource(string $name, string $controller, array $options = []): \Qubus\Routing\Interfaces\Routable
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | |
$controller | string | |
$options | array |
loadRoutesFromJson
Load routes from a JSON file.
Parameters:
Parameter | Type | Description |
---|---|---|
$path | string | Path to the JSON routes file. |
Throws:
handleSimpleJsonRoutes
Converts JSON routes to a route object.
Parameters:
Parameter | Type | Description |
---|---|---|
$route | array | Array from JSON file. |
Throws:
handleGroupJsonRoutes
Converts JSON group routes to a route object.
Parameters:
Parameter | Type | Description |
---|---|---|
$route | array | Array form JSON file. |
Throws:
createRoutes
match
Match a given Request Url against stored routes converted into a Response.
public match(\Psr\Http\Message\ServerRequestInterface $serverRequest): \Psr\Http\Message\ResponseInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$serverRequest | \Psr\Http\Message\ServerRequestInterface |
Throws:
handle
protected handle(object $route, \Psr\Http\Message\ServerRequestInterface $serverRequest, \Qubus\Routing\Route\RouteParams $params): \Psr\Http\Message\ResponseInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$route | object | |
$serverRequest | \Psr\Http\Message\ServerRequestInterface | |
$params | \Qubus\Routing\Route\RouteParams |
addBootManager
Add BootManager
Parameters:
Parameter | Type | Description |
---|---|---|
$bootManager | \Qubus\Routing\Interfaces\BootManager |
has
Check if a route exists based on its name.
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | The name of the route. |
Return Value:
True if the named routed exists, false otherwise.
url
Generate url's from named routes.
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | Name of the route. |
$params | array | Data parameters. |
Return Value:
The url.
redirect
Redirect one route to another.
Parameters:
Parameter | Type | Description |
---|---|---|
$from | string | Originating route. |
$to | string | Destination route. |
$status | int | HTTP status code. |
permanentRedirect
Create a permanent redirect from one URI to another.
public permanentRedirect(string $uri, string $destination): \Qubus\Routing\Interfaces\Routable|\Qubus\Routing\Interfaces\Mappable
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$destination | string |
Throws:
group
Add route group
Parameters:
Parameter | Type | Description |
---|---|---|
$params | array|string | |
$callback | callable |
getBasePath
Get the basepath.
Return Value:
The basepath.
currentRoute
Get current route.
Return Value:
Current route.
currentRouteName
Get current route name.
Return Value:
Current route name.
setEventHandlers
Register event handler
Parameters:
Parameter | Type | Description |
---|---|---|
$handler | \Qubus\Routing\Events\EventHandler |
getEventHandlers
Get registered event-handler.
fireEvents
Fire event in event-handler.
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | |
$arguments | array |
setExtrasOfSimpleJsonRoute
Sets other router methods.
Parameters:
Parameter | Type | Description |
---|---|---|
$extras | array | Router attributes. |
$route | \Qubus\Routing\Interfaces\Routable | Route object. |
Throws:
process
public process(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$request | \Psr\Http\Message\ServerRequestInterface | |
$handler | \Psr\Http\Server\RequestHandlerInterface |
Throws:
Inherited methods
map
Add a route to the map.
public map(array $verbs, string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$verbs | array | |
$uri | string | |
$callback | callable|string |
any
Add a route that responds to any HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
get
Add a route that responds to GET HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
post
Add a route that responds to POST HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
patch
Add a route that responds to PATCH HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
put
Add a route that responds to PUT HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
delete
Add a route that responds to DELETE HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
head
Add a route that responds to HEAD HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
options
Add a route that responds to OPTIONS HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
connect
Add a route that responds to CONNECT HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
trace
Add a route that responds to TRACE HTTP method.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri | string | |
$callback | callable|string |
Throws:
Automatically generated on 2025-10-13