Oihana PHP

Route uses AppTrait, ContainerTrait, LoggerTrait, ToStringTrait

Represents a route definition and handles route creation and execution.

A Route is the base building block of the routing layer: it stores the route pattern, its name (prefix/suffix), the associated controller identifier and an optional set of nested route definitions. Invoking the instance walks the nested definitions and registers each resolved route, while Route::create() turns a plain definition array into a concrete route object.

Subclasses such as HttpMethodRoute and DocumentRoute specialize this behaviour for individual HTTP verbs or full CRUD resources.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

APP  : string = 'app'
Array keys for route initialization
CLAZZ  : string = 'clazz'
CONTROLLER_ID  : string = 'controllerID'
DEFAULT_OWNER_PLACEHOLDER  : string = 'owner:[0-9]+'
Default owner pattern for numeric owner IDs
DEFAULT_PREFIX  : string = 'api'
Default API prefix for route names
DEFAULT_ROUTE_PLACEHOLDER  : string = 'id:[0-9]+'
Default route pattern for numeric IDs
FLAGS  : string = 'flags'
METHOD  : string = 'method'
NAME  : string = 'name'
OWNER_PATTERN  : string = 'ownerPattern'
OWNER_PLACEHOLDER  : string = 'ownerPlaceHolder'
PATCH_PATTERN  : string = 'patchPattern'
PATCH_PLACE_HOLDER  : string = 'patchPlaceHolder'
PREFIX  : string = 'prefix'
PROPERTY  : string = 'property'
ROUTE  : string = 'route'
ROUTE_PATTERN  : string = 'routePattern'
ROUTE_PLACEHOLDER  : string = 'routePattern'
ROUTES  : string = 'routes'
SUFFIX  : string = 'suffix'

Properties

$controllerID  : string|null
$name  : string|null
$ownerPlaceholder  : string|null
$prefix  : string
$property  : string
$route  : string|null
$routePlaceholder  : string
$routes  : array<string|int, mixed>|null
$suffix  : string

Methods

__construct()  : mixed
Initializes a route instance with optional parameters.
__invoke()  : void
Invokes all nested routes if defined.
create()  : Route|null
Creates a new Route instance from a definition array or Route object.
dotify()  : string
Converts a route path from 'foo/bar' to 'foo.bar'.
execute()  : void
Executes a callable or an array of callables.
getName()  : string
Returns the fully qualified route name, including prefix and suffix.
getRoute()  : string
Returns the safe main route representation starting with '/'.

Constants

APP

Array keys for route initialization

public string APP = 'app'

CLAZZ

public string CLAZZ = 'clazz'

CONTROLLER_ID

public string CONTROLLER_ID = 'controllerID'

DEFAULT_OWNER_PLACEHOLDER

Default owner pattern for numeric owner IDs

public string DEFAULT_OWNER_PLACEHOLDER = 'owner:[0-9]+'

DEFAULT_PREFIX

Default API prefix for route names

public string DEFAULT_PREFIX = 'api'

DEFAULT_ROUTE_PLACEHOLDER

Default route pattern for numeric IDs

public string DEFAULT_ROUTE_PLACEHOLDER = 'id:[0-9]+'

FLAGS

public string FLAGS = 'flags'

METHOD

public string METHOD = 'method'

NAME

public string NAME = 'name'

OWNER_PATTERN

public string OWNER_PATTERN = 'ownerPattern'

OWNER_PLACEHOLDER

public string OWNER_PLACEHOLDER = 'ownerPlaceHolder'

PATCH_PATTERN

public string PATCH_PATTERN = 'patchPattern'

PATCH_PLACE_HOLDER

public string PATCH_PLACE_HOLDER = 'patchPlaceHolder'

PREFIX

public string PREFIX = 'prefix'

PROPERTY

public string PROPERTY = 'property'

ROUTE

public string ROUTE = 'route'

ROUTE_PATTERN

public string ROUTE_PATTERN = 'routePattern'

ROUTE_PLACEHOLDER

public string ROUTE_PLACEHOLDER = 'routePattern'

ROUTES

public string ROUTES = 'routes'

SUFFIX

public string SUFFIX = 'suffix'

Properties

$controllerID

public string|null $controllerID = null

Controller ID registered in DI container

$name

public string|null $name = null

Route name

$ownerPlaceholder

public string|null $ownerPlaceholder = self::DEFAULT_OWNER_PLACEHOLDER

The owner route placeholder.

$prefix

public string $prefix = self::DEFAULT_PREFIX

Route name prefix

$property

public string $property = \oihana\enums\Char::EMPTY

Property name in complex routes

$route

public string|null $route = null

The route expression.

$routePlaceholder

public string $routePlaceholder = self::DEFAULT_ROUTE_PLACEHOLDER

The route placeholder.

$routes

public array<string|int, mixed>|null $routes = null

Nested route definitions.

$suffix

public string $suffix = \oihana\enums\Char::EMPTY

Route name suffix

Methods

__construct()

Initializes a route instance with optional parameters.

public __construct(Container $container[, array<string|int, mixed> $init = [] ]) : mixed
Parameters
$container : Container

DI container

$init : array<string|int, mixed> = []

Optional route initialization array:

  • 'controllerID': Optional controller identifier.
  • 'name': Optional route name (defaults to generated name).
  • 'ownerPattern': Optional owner route pattern (default '{owner:[0-9]+}').
  • 'prefix': Optional prefix for route name.
  • 'property': Optional property name in complex routes.
  • 'route': Optional main route pattern.
  • 'routePattern': Optional route regex pattern (default '{id:[0-9]+}').
  • 'routes': Optional nested route definitions to initialize.
  • 'suffix': Optional suffix for route name.
  • 'verbose': Optional verbose mode (default true).
Tags
throws
DependencyException

If a dependency cannot be resolved by the container.

NotFoundException

If the requested entry is not found in the container.

ContainerExceptionInterface

If the container encounters an error while retrieving an entry.

NotFoundExceptionInterface

If no entry was found in the container for the given identifier.

__invoke()

Invokes all nested routes if defined.

public __invoke() : void
Tags
throws
DependencyException

If a dependency cannot be resolved by the container.

NotFoundException

If the requested entry is not found in the container.

create()

Creates a new Route instance from a definition array or Route object.

public create(array<string|int, mixed>|Route|null $definition) : Route|null
Parameters
$definition : array<string|int, mixed>|Route|null

Route definition or existing Route

Return values
Route|null

The created Route instance or null if invalid

dotify()

Converts a route path from 'foo/bar' to 'foo.bar'.

public dotify(string $route) : string
Parameters
$route : string

Route path

Return values
string

Dotified route path

execute()

Executes a callable or an array of callables.

public execute(mixed $routes) : void
Parameters
$routes : mixed

Callable or array of callables

getName()

Returns the fully qualified route name, including prefix and suffix.

public getName() : string
Return values
string

Route name

getRoute()

Returns the safe main route representation starting with '/'.

public getRoute() : string
Return values
string

Route path

On this page

Search results