OptionsRoute extends Route
Represents a route that registers an HTTP OPTIONS verb.
This class is typically used for CORS preflight requests.
It extends the base Route class and registers an options route
using the responsePassthrough helper, which simply returns the
response (often modified by middleware) without any further processing.
Tags
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
- $loggable : bool
- The loggable flag.
- $name : string|null
- $ownerPlaceholder : string|null
- $prefix : string
- $property : string
- $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
- Called when a script tries to call the instance as a function.
- __toString() : string
- Returns a String representation of the object.
- alert() : void
- Action must be taken immediately.
- create() : Route|null
- Creates a new Route instance from a definition array or Route object.
- critical() : void
- Critical conditions.
- debug() : void
- Detailed debug information.
- 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.
- 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.
- log() : void
- Logs with an arbitrary level.
- notice() : void
- Normal but significant events.
- 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
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
__invoke()
Called when a script tries to call the instance as a function.
public
__invoke() : void
__toString()
Returns a String representation of the object.
public
__toString() : string
Tags
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> = []
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> = []
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
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|nullgetName()
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:
- From the provided initialization array (e.g., ['app' => App instance]).
- 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
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
Return values
staticinitializeLogger()
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
nullor an empty value, which will default to LoggerInterface::class depending on the$useDefaultparameter.
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
$initdoes not provide a valid logger string. Defaults totrue.
Tags
Return values
static —Returns the current instance for method chaining.
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> = []
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> = []
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> = []