Oihana PHP System

DocumentRoute extends Route uses HttpMethodRoutesTrait

Represents a route definition and handles route creation and execution.

Table of Contents

Constants

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

Properties

$container  : Container
The DI container reference.
$controllerID  : string|null
$delete  : string|null
$get  : string|null
$list  : string|null
$loggable  : bool
The loggable flag.
$name  : string|null
$ownerPlaceholder  : string|null
$patch  : string|null
$post  : string|null
$prefix  : string
$property  : string
$put  : string|null
$route  : string|null
$routePlaceholder  : string
$routes  : array<string|int, mixed>|null
$suffix  : string
$app  : App
The Slim App instance.

Methods

__construct()  : mixed
Initializes a route instance with optional parameters.
__invoke()  : void
Initialize the current route.
__toString()  : string
Returns a String representation of the object.
alert()  : void
Action must be taken immediately.
count()  : void
Generates a special GET count route reference.
create()  : Route|null
Creates a new Route instance from a definition array or Route object.
critical()  : void
Critical conditions.
debug()  : void
Detailed debug information.
delete()  : void
Generates a new DELETE route reference.
dotify()  : string
Converts a route path from 'foo/bar' to 'foo.bar'.
emergency()  : void
System is unusable.
error()  : void
Runtime errors that do not require immediate action but should typically be logged and monitored.
execute()  : void
Executes a callable or an array of callables.
get()  : void
Generates a new GET route reference.
getBasePath()  : string
Returns the base path of the application.
getLogger()  : LoggerInterface|null
Returns the logger reference.
getName()  : string
Returns the fully qualified route name, including prefix and suffix.
getRoute()  : string
Returns the safe main route representation starting with '/'.
getUrl()  : string
Generates a full URL for the application.
info()  : void
Interesting events.
initializeApp()  : static
Initializes the internal `app` property.
initializeLoggable()  : static
Initialize the loggable flag.
initializeLogger()  : static
Initializes the logger reference for the current instance.
initializeMethods()  : static
Initializes or overrides HTTP method handlers based on the given init array.
list()  : void
Generates a new GET (LIST) route reference.
log()  : void
Logs with an arbitrary level.
method()  : void
notice()  : void
Normal but significant events.
options()  : void
Generates a new OPTIONS route reference.
patch()  : void
Generates a new PATCH route reference.
post()  : void
Generates a new POST route reference.
put()  : void
Generates a new PUT route reference.
warning()  : void
Exceptional occurrences that are not errors.

Constants

APP

Array keys for route initialization

public mixed APP = 'app'

CLAZZ

public mixed CLAZZ = 'clazz'

CONTROLLER_ID

public mixed CONTROLLER_ID = 'controllerID'

DEFAULT_OWNER_PLACEHOLDER

Default owner pattern for numeric owner IDs

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

DEFAULT_PREFIX

Default API prefix for route names

public mixed DEFAULT_PREFIX = 'api'

DEFAULT_ROUTE_PLACEHOLDER

Default route pattern for numeric IDs

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

FLAGS

public mixed FLAGS = 'flags'

LOGGABLE

The 'loggable' parameter constant.

public mixed LOGGABLE = 'loggable'

LOGGER

The 'logger' parameter constant.

public mixed LOGGER = 'logger'

METHOD

public mixed METHOD = 'method'

NAME

public mixed NAME = 'name'

OWNER_PATTERN

public mixed OWNER_PATTERN = 'ownerPattern'

OWNER_PLACEHOLDER

public mixed OWNER_PLACEHOLDER = 'ownerPlaceHolder'

PATCH_PATTERN

public mixed PATCH_PATTERN = 'patchPattern'

PATCH_PLACE_HOLDER

public mixed PATCH_PLACE_HOLDER = 'patchPlaceHolder'

PREFIX

public mixed PREFIX = 'prefix'

PROPERTY

public mixed PROPERTY = 'property'

ROUTE

public mixed ROUTE = 'route'

ROUTE_PATTERN

public mixed ROUTE_PATTERN = 'routePattern'

ROUTE_PLACEHOLDER

public mixed ROUTE_PLACEHOLDER = 'routePattern'

ROUTES

public mixed ROUTES = 'routes'

SUFFIX

public mixed SUFFIX = 'suffix'

Properties

$container

The DI container reference.

public Container $container

$controllerID

public string|null $controllerID = null

Controller ID registered in DI container

$loggable

The loggable flag.

public bool $loggable = false

$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

$app

The Slim App instance.

protected App $app
Tags
access

protected

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).

__invoke()

Initialize the current route.

public __invoke() : void
Tags
throws
DependencyException
throws
NotFoundException
throws
ContainerExceptionInterface
throws
NotFoundExceptionInterface

__toString()

Returns a String representation of the object.

public __toString() : string
Tags
throws
ReflectionException
Return values
string

A string representation of the object.

alert()

Action must be taken immediately.

public alert(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

count()

Generates a special GET count route reference.

public count(array<string|int, mixed> &$routes, string $route[, string|null $method = HttpMethod::count ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$method : string|null = HttpMethod::count

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

critical()

Critical conditions.

public critical(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: Application component unavailable, unexpected exception.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

debug()

Detailed debug information.

public debug(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

delete()

Generates a new DELETE route reference.

public delete(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$method : string|null = null

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

emergency()

System is unusable.

public emergency(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

error()

Runtime errors that do not require immediate action but should typically be logged and monitored.

public error(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

execute()

Executes a callable or an array of callables.

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

Callable or array of callables

get()

Generates a new GET route reference.

public get(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$method : string|null = null

getBasePath()

Returns the base path of the application.

public getBasePath() : string

This corresponds to the path configured in Slim and can be used to generate URLs relative to the application root.

Return values
string

The application's base path (e.g., "/myapp")

getLogger()

Returns the logger reference.

public getLogger() : LoggerInterface|null
Return values
LoggerInterface|null

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

getUrl()

Generates a full URL for the application.

public getUrl([string $path = '' ][, array<string|int, mixed> $params = [] ][, bool $useNow = false ]) : string

The URL is constructed using the application's base URL, the base path, the optional path, and query parameters.

Parameters
$path : string = ''

Optional relative path to append to the base URL.

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

Optional query parameters as key-value pairs.

$useNow : bool = false

If true, timestamp-like parameters will be processed immediately.

Return values
string

The full URL including base URL, path, and query parameters.

info()

Interesting events.

public info(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: User logs in, SQL logs.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

initializeApp()

Initializes the internal `app` property.

public initializeApp([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

This method retrieves the Slim App instance with a specific priority:

  1. From the provided initialization array (e.g., ['app' => App instance]).
  2. If not in the array, from the DI container (using App::class or a custom key from init).

It throws an exception if no valid App instance can be found. This priority allows for easy overriding/mocking during tests.

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

Optional initialization array.

$container : ContainerInterface|null = null

Optional DI container.

Tags
throws
NotFoundExceptionInterface

If the container is used and the App class is not found.

throws
ContainerExceptionInterface

If the container throws an internal error.

throws
RuntimeException

If no valid App instance is provided or found.

Return values
static

Returns the current controller instance for method chaining.

initializeLoggable()

Initialize the loggable flag.

public initializeLoggable([bool|array<string|int, mixed>|null $init = null ][, ContainerInterface|null $container = null ][, bool|array<string|int, mixed>|null $defaultValue = false ]) : static
Parameters
$init : bool|array<string|int, mixed>|null = null

The definition to initialize the loggable property.

$container : ContainerInterface|null = null
$defaultValue : bool|array<string|int, mixed>|null = false

The default value if the $init argument is not defined.

Tags
throws
ContainerExceptionInterface
throws
NotFoundExceptionInterface
Return values
static

initializeLogger()

Initializes the logger reference for the current instance.

public initializeLogger([array<string|int, mixed>|LoggerInterface|string|null $init = null ][, ContainerInterface|null $container = null ][, bool $useDefault = true ]) : static

This method accepts either:

  • A LoggerInterface instance
  • An associative array containing a logger reference under the static::LOGGER key
  • A string representing a service ID or class name resolvable by the container
  • null or an empty value, which will default to LoggerInterface::class depending on the $useDefault parameter.

If a dependency injection container is provided, the method will attempt to resolve the logger service from it. If no valid logger can be resolved, the $this->logger property will be set to null.

Parameters
$init : array<string|int, mixed>|LoggerInterface|string|null = null

Logger initialization data. May be an instance, an array with a logger entry, a string service ID/class name, or null.

$container : ContainerInterface|null = null

Optional dependency injection container used to resolve the logger service.

$useDefault : bool = true

Whether to use LoggerInterface::class as a fallback if $init does not provide a valid logger string. Defaults to true.

Tags
throws
DependencyException

If there is a dependency resolution error.

throws
NotFoundException

If the specified service is not found in the container.

throws
NotFoundExceptionInterface

If the specified service is not found in the container.

throws
ContainerExceptionInterface

If the container encounters a general error.

Return values
static

Returns the current instance for method chaining.

initializeMethods()

Initializes or overrides HTTP method handlers based on the given init array.

public initializeMethods([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []

Initialization or override parameters.

Return values
static

list()

Generates a new GET (LIST) route reference.

public list(array<string|int, mixed> &$routes, string $route[, string|null $method = HttpMethod::list ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$method : string|null = HttpMethod::list

log()

Logs with an arbitrary level.

public log(mixed $level, string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$level : mixed
$message : string|Stringable
$context : array<string|int, mixed> = []

method()

public method(string $clazz, array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
$clazz : string
$routes : array<string|int, mixed>
$route : string
$method : string|null = null
Tags
protected

notice()

Normal but significant events.

public notice(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

options()

Generates a new OPTIONS route reference.

public options(array<string|int, mixed> &$routes, string $route[, bool $flag = true ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$flag : bool = true
Tags
throws
DependencyException
throws
NotFoundException
throws
ContainerExceptionInterface
throws
NotFoundExceptionInterface

patch()

Generates a new PATCH route reference.

public patch(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$method : string|null = null

post()

Generates a new POST route reference.

public post(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$method : string|null = null

put()

Generates a new PUT route reference.

public put(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
$routes : array<string|int, mixed>
$route : string
$method : string|null = null

warning()

Exceptional occurrences that are not errors.

public warning(string|Stringable $message[, array<string|int, mixed> $context = [] ]) : void

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Parameters
$message : string|Stringable
$context : array<string|int, mixed> = []

        
On this page

Search results