com\setasign\SetaFramework\Router

Router Class Router

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

Class hierarchy

Implements

  • \Psr\Log\LoggerAwareInterface

Summary

Constants

DEFAULT_PRIORITY

public const AbstractRouter::DEFAULT_PRIORITY = 50

Properties

$defaultValues

protected array<string, mixed> Router::$defaultValues

$logger

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

Methods

__construct()

public Router::__construct (
array<string, mixed> $defaultValues = array ( )
)

Constructor

Parameters
$defaultValues : array<string, mixed>

<string,mixed>

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 Router::process (
\Psr\Http\Message\RequestInterface $request
): array

Tests all routes

The returned data of the route will be merged with the Router::defaultValues array with the priority on the values from the route

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

Throws RouteException

resolveAppendingRoutes()

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

resolvePrependingRoutes()

Parameters
$name : string
 

setDefaultValue()

public Router::setDefaultValue (
string $key,
mixed $value
): void

Sets a key of the Router::defaultValues array

Parameters
$key : string

The key shouldn't be a natural number

$value : mixed
 

setDefaultValues()

public Router::setDefaultValues (
array<string, mixed> $defaultValues
): void

Overwrites the Router::defaultValues array

Parameters
$defaultValues : array<string, mixed>

The keys of this array shouldn't be natural numbers

setLogger()

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

Sets a logger instance on the object.

Parameters
$logger : \Psr\Log\LoggerInterface