Skip to content

RoutingCallback

RoutingCallback allows you to provide callbacks into the routing

abstract class RoutingCallback extends ParameterHolder

ExtendsParameterHolder
Since1.0.0
SourceRouting/RoutingCallback.php
PropertyTypeDescription
$contextmixedprotected.
$routemixedprotected.
MethodDescription
getContext(): ContextRetrieve the current application context.
initialize(Context $context, array<mixed, mixed> &$route): voidInitialize the callback instance.
onGenerate(array<mixed, mixed> $defaultParameters, array<mixed, mixed> &$userParameters, array<mixed, mixed> &$userOptions): boolGets executed when the route of this callback is about to be reverse generated into an URL.
onMatched(array<string, mixed> &$parameters, mixed $legacyContainer = null): boolExecuted when the route matched (container-less).
onNotMatched(mixed $legacyContainer = null): voidExecuted when the route did NOT match (container-less).
reset(): voidReturns the callback to its uninitialized state.

final public function getContext(): Context

Retrieve the current application context.

Returns Context — An Context instance.

ThrowsWhen
InitializationExceptionIf this RoutingCallback has not been initialized yet.

public function initialize(Context $context, array<mixed, mixed> &$route): void

Initialize the callback instance.

An array with information about the route.

ParameterTypeDescription
$contextContextAn Context instance.
$routearray``<``mixed``, ``mixed``>An array with information about the route.

public function onGenerate(array<mixed, mixed> $defaultParameters, array<mixed, mixed> &$userParameters, array<mixed, mixed> &$userOptions): bool

Gets executed when the route of this callback is about to be reverse generated into an URL.

The options the user supplied to Routing::gen().

ParameterTypeDescription
$defaultParametersarray``<``mixed``, ``mixed``>The default parameters stored in the route.
$userParametersarray``<``mixed``, ``mixed``>The parameters the user supplied to Routing::gen().
$userOptionsarray``<``mixed``, ``mixed``>The options the user supplied to Routing::gen().

Returns bool — Whether this route part should be generated.

public function onMatched(array<string, mixed> &$parameters, mixed $legacyContainer = null): bool

Executed when the route matched (container-less).

Unused; retained for signature compatibility.

ParameterTypeDescription
$parametersarray``<``string``, ``mixed``>Parameters generated by this route (modifiable).
$legacyContainermixedUnused; retained for signature compatibility.

Returns bool — true to accept match; false to treat as not matched.

public function onNotMatched(mixed $legacyContainer = null): void

Executed when the route did NOT match (container-less).

Unused; retained for signature compatibility.

ParameterTypeDescription
$legacyContainermixedUnused; retained for signature compatibility.

public function reset(): void

Returns the callback to its uninitialized state.

Drops the context and route references handed in by RoutingCallback::initialize() and clears every parameter held on the instance, so a container-managed callback can be reused for the next request without carrying anything over. RoutingCallback::getContext() throws again afterwards until the callback is initialized once more.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
removeParameter()ParameterHolderRemove a parameter.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.