Skip to content

Router

Properties

request

public \Qubus\Http\Request $request

version

public string $version

routes

public array $routes

routeCollector

protected \Qubus\Routing\Interfaces\Collector $routeCollector

routesCreated

protected bool $routesCreated

routeCollectorMatchTypeId

protected int $routeCollectorMatchTypeId

basePath

protected string $basePath

currentRoute

protected ?\Qubus\Routing\Route\Route $currentRoute

container

protected ?\Psr\Container\ContainerInterface $container

responseFactory

protected ?\Psr\Http\Message\ResponseFactoryInterface $responseFactory

middlewareResolver

protected ?\Qubus\Routing\Interfaces\MiddlewareResolver $middlewareResolver

invoker

protected ?\Qubus\Routing\Invoker $invoker

baseMiddleware

public array $baseMiddleware

defaultNamespace

protected ?string $defaultNamespace

namespace

protected string $namespace

bootManagers

protected array $bootManagers

eventHandlers

protected array $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

public prependUrl(string $url): void

Parameters:

Parameter Type Description
$url string

setContainer

Set a container.

protected setContainer(\Psr\Container\ContainerInterface $container): void

Parameters:

Parameter Type Description
$container \Psr\Container\ContainerInterface

setBasePath

Set the basepath.

public setBasePath(string $basePath): void

Parameters:

Parameter Type Description
$basePath string

setDefaultNamespace

Set the default namespace for controllers.

public setDefaultNamespace(string $namespace): void

Parameters:

Parameter Type Description
$namespace string

addRoute

Add route.

protected addRoute(\Qubus\Routing\Route\Route $route): void

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

public map(array $verbs, string $uri, callable|string $callback): \Qubus\Routing\Route\Route

Parameters:

Parameter Type Description
$verbs array HTTP methods.
$uri string Route path.
$callback callable|string

Throws:


resources

Register an array of resource controllers.

public resources(array $resources, array $options = []): void

Parameters:

Parameter Type Description
$resources array
$options array

resource

Route a resource to a controller.

public resource(string $name, string $controller, array $options = []): mixed

Parameters:

Parameter Type Description
$name string
$controller string
$options array

apiResources

Register an array of API resource controllers.

public apiResources(array $resources, array $options = []): void

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.

public loadRoutesFromJson(string $path): void

Parameters:

Parameter Type Description
$path string Path to the JSON routes file.

Throws:


handleSimpleJsonRoutes

Converts JSON routes to a route object.

public handleSimpleJsonRoutes(array $route): void

Parameters:

Parameter Type Description
$route array Array from JSON file.

Throws:


handleGroupJsonRoutes

Converts JSON group routes to a route object.

public handleGroupJsonRoutes(array $route): void

Parameters:

Parameter Type Description
$route array Array form JSON file.

Throws:


createRoutes

protected createRoutes(): void

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

public addBootManager(\Qubus\Routing\Interfaces\BootManager $bootManager): static

Parameters:

Parameter Type Description
$bootManager \Qubus\Routing\Interfaces\BootManager

has

Check if a route exists based on its name.

public has(string $name): bool

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.

public url(string $name, array $params = []): string

Parameters:

Parameter Type Description
$name string Name of the route.
$params array Data parameters.

Return Value:

The url.


redirect

Redirect one route to another.

public redirect(string $from, string $to, int $status = 302): \Qubus\Routing\Interfaces\Routable

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

public group(array|string $params, callable $callback): self

Parameters:

Parameter Type Description
$params array|string
$callback callable

getBasePath

Get the basepath.

public getBasePath(): string

Return Value:

The basepath.


currentRoute

Get current route.

public currentRoute(): \Qubus\Routing\Route\Route|null

Return Value:

Current route.


currentRouteName

Get current route name.

public currentRouteName(): null|string

Return Value:

Current route name.


setEventHandlers

Register event handler

public setEventHandlers(\Qubus\Routing\Events\EventHandler $handler): void

Parameters:

Parameter Type Description
$handler \Qubus\Routing\Events\EventHandler

getEventHandlers

Get registered event-handler.

public getEventHandlers(): array

fireEvents

Fire event in event-handler.

protected fireEvents(string $name, array $arguments = []): void

Parameters:

Parameter Type Description
$name string
$arguments array

setExtrasOfSimpleJsonRoute

Sets other router methods.

private setExtrasOfSimpleJsonRoute(array $extras, \Qubus\Routing\Interfaces\Routable $route): void

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.

public any(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


get

Add a route that responds to GET HTTP method.

public get(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


post

Add a route that responds to POST HTTP method.

public post(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


patch

Add a route that responds to PATCH HTTP method.

public patch(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


put

Add a route that responds to PUT HTTP method.

public put(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


delete

Add a route that responds to DELETE HTTP method.

public delete(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


Add a route that responds to HEAD HTTP method.

public head(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


options

Add a route that responds to OPTIONS HTTP method.

public options(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


connect

Add a route that responds to CONNECT HTTP method.

public connect(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:


trace

Add a route that responds to TRACE HTTP method.

public trace(string $uri, callable|string $callback): \Qubus\Routing\Interfaces\Routable

Parameters:

Parameter Type Description
$uri string
$callback callable|string

Throws:



Automatically generated on 2025-10-13