I18nRoute extends DocumentRoute
Registers the routes used to read and update a localized (i18n) property of a document.
Unlike DocumentRoute, which exposes the whole resource, an I18nRoute
targets a single translatable property nested under an item identifier. It
builds the pattern /route/{id}/property and registers the OPTIONS, GET
and PATCH verbs for it, the GET/PATCH controller methods being derived
from the configured property name.
Tags
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
- $delete : string|null
- $get : string|null
- $list : string|null
- $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
Methods
- __construct() : mixed
- Creates a new DocumentRoute instance.
- __invoke() : void
- Registers the OPTIONS, GET and PATCH routes for the localized property.
- count() : void
- Generates a special GET count route reference.
- create() : Route|null
- Creates a new Route instance from a definition array or Route object.
- delete() : void
- Generates a new DELETE route reference.
- dotify() : string
- Converts a route path from 'foo/bar' to 'foo.bar'.
- execute() : void
- Executes a callable or an array of callables.
- get() : void
- Generates a new GET route reference.
- getName() : string
- Returns the fully qualified route name, including prefix and suffix.
- getRoute() : string
- Returns the safe main route representation starting with '/'.
- initializeMethods() : static
- Initializes or overrides HTTP method handlers based on the given init array.
- list() : void
- Generates a new GET (LIST) route reference.
- method() : void
- Instantiates a route of the given class and appends it to the accumulator.
- 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.
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
$delete
public
string|null
$delete
= null
$get
public
string|null
$get
= null
$list
public
string|null
$list
= null
$name
public
string|null
$name
= null
Route name
$ownerPlaceholder
public
string|null
$ownerPlaceholder
= self::DEFAULT_OWNER_PLACEHOLDER
The owner route placeholder.
$patch
public
string|null
$patch
= null
$post
public
string|null
$post
= null
$prefix
public
string
$prefix
= self::DEFAULT_PREFIX
Route name prefix
$property
public
string
$property
= \oihana\enums\Char::EMPTY
Property name in complex routes
$put
public
string|null
$put
= null
$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()
Creates a new DocumentRoute instance.
public
__construct(Container $container[, array<string|int, mixed> $init = [] ]) : mixed
Parameters
- $container : Container
-
The DI container reference.
- $init : array<string|int, mixed> = []
-
Optional route initialization array (see Route::__construct()), also accepting
flagsand per-verb method overrides.
Tags
__invoke()
Registers the OPTIONS, GET and PATCH routes for the localized property.
public
__invoke() : void
If the configured controller is not registered in the DI container, a warning is logged and no route is created.
Tags
count()
Generates a special GET count route reference.
public
count(array<string|int, mixed> &$routes, string $route[, string|null $method = HttpMethod::count ]) : void
Only appended when the COUNT flag is enabled; the /count suffix is added
automatically to the given route.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The base route path.
- $method : string|null = HttpMethod::count
-
The controller method to invoke (defaults to the
countmethod).
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
delete()
Generates a new DELETE route reference.
public
delete(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the DELETE flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured delete method).
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
get()
Generates a new GET route reference.
public
get(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the GET flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured get method).
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
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, keyed by HTTP verb.
Return values
static —Returns the current instance for method chaining.
list()
Generates a new GET (LIST) route reference.
public
list(array<string|int, mixed> &$routes, string $route[, string|null $method = HttpMethod::list ]) : void
Only appended when the LIST flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = HttpMethod::list
-
The controller method to invoke (defaults to the
listmethod).
method()
Instantiates a route of the given class and appends it to the accumulator.
public
method(string $clazz, array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Parameters
- $clazz : string
-
The fully qualified route class to instantiate (must extend Route).
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke for this route, if any.
Tags
options()
Generates a new OPTIONS route reference.
public
options(array<string|int, mixed> &$routes, string $route[, bool $flag = true ]) : void
The route is only appended when $flag is true, which lets callers
conditionally expose the OPTIONS verb depending on the other enabled routes.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $flag : bool = true
-
Whether the OPTIONS route should actually be created (default
true).
Tags
patch()
Generates a new PATCH route reference.
public
patch(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the PATCH flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured patch method).
post()
Generates a new POST route reference.
public
post(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the POST flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured post method).
put()
Generates a new PUT route reference.
public
put(array<string|int, mixed> &$routes, string $route[, string|null $method = null ]) : void
Only appended when the PUT flag is enabled.
Parameters
- $routes : array<string|int, mixed>
-
Reference to the routes accumulator to append to.
- $route : string
-
The route path to register.
- $method : string|null = null
-
The controller method to invoke (defaults to the configured put method).