com\setasign\SetaFramework\Router

AbstractRouter Class AbstractRouter

File: /SetaFramework/src/Router/AbstractRouter.php

Class hierarchy

Implements

  • \Psr\Log\LoggerAwareInterface

Summary

Constants

DEFAULT_PRIORITY

public const AbstractRouter::DEFAULT_PRIORITY = 50

Properties

$appendingRoutes

private AbstractRouter::$appendingRoutes = array()

$logger

protected ?\Psr\Log\LoggerInterface AbstractRouter::$logger

$prependingRoutes

$routes

private array<string, Route\RouteInterface> AbstractRouter::$routes = array()

Containing all routes with the name as key


Methods

appendRoute()

public AbstractRouter::appendRoute (
string $name,
Route\RouteInterface $route,
string $after = '',
int $priority = AbstractRouter::DEFAULT_PRIORITY
): self

Append a route after the route $after.

If $after is an empty string than the added route will be the last route.

The name of the route need to be unique.

Parameters
$name : string

Name of the new route

$route : Route\RouteInterface

Route

$after : string

Append this route after the route with this name

$priority : int
 
Exceptions

Throws RouteException

getRoute()

public AbstractRouter::getRoute (
string $routeName
): Route\RouteInterface

Returns a route

Parameters
$routeName : string
 
Exceptions

Throws \InvalidArgumentException

getRoutes()

public AbstractRouter::getRoutes (
void
): array

Returns all routes in the correct order

Exceptions

Throws RouteException

prependRoute()

public AbstractRouter::prependRoute (
string $name,
Route\RouteInterface $route,
string $before = '',
int $priority = AbstractRouter::DEFAULT_PRIORITY
): self

Prepend a route before the route $before.

If $before is an empty string than the added route will be the first route.

The name of the route need to be unique.

Parameters
$name : string

Name of the new route

$route : Route\RouteInterface

Route

$before : string

Prepend this route before the route with this name

$priority : int
 
Exceptions

Throws RouteException

process()

public AbstractRouter::process (
\Psr\Http\Message\RequestInterface $request
): array

Calls the match-method of all routes in the correct order and break if one route is matching

The result of a matching route will be merged with the default values of this and will be returned

Parameters
$request : \Psr\Http\Message\RequestInterface
 
Exceptions

Throws RouteException

resolveAppendingRoutes()

protected AbstractRouter::resolveAppendingRoutes (
string $name
): \Generator
Parameters
$name : string
 

resolvePrependingRoutes()

Parameters
$name : string
 

setLogger()

public AbstractRouter::setLogger (
\Psr\Log\LoggerInterface $logger
): void

Sets a logger instance on the object.

Parameters
$logger : \Psr\Log\LoggerInterface