Skip to content

HttpRedirectRoutingCallback

HttpRedirectRoutingCallback allows redirection of a matched route to a route or URL.

Matched arguments can be rewritten. You need to configure this callback using parameters in the block. To redirect to a URL, use the “url” configuration parameter and supply the destination URL as the value. To redirect to a route, use the “route” configuration parameter and supply the name of the route to generate. You may pass an arbitrary array of arguments in parameter “arguments”. If a parameter value contains a valid PHP variable literal such as $foo, ${foo} or {$foo}, the literal will be replaced with the value of the argument “foo” in the matched route the callback is defined on. Default routing gen() options for generating are “relative” set to false and “separator” set to ”&”. You may pass an array of options or the name of a routing gen() options preset in configuration in parameter “options”. By default, the HTTP status code 302 is used for redirects. You can define a different status code through configuration parameter “code”.

class HttpRedirectRoutingCallback extends RoutingCallback

ExtendsRoutingCallback
Since1.0.0
SourceRouting/HttpRedirectRoutingCallback.php
MethodDescription
initialize(Context $context, array<mixed, mixed> &$route): voidInitialize the callback instance.
[`onMatched(array<string, mixed> &$parameters, mixed $legacyContainer = null): boolWebResponse`](#onmatched)

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 onMatched(array<string, mixed> &$parameters, mixed $legacyContainer = null): bool|WebResponse

Container-less match hook.

Unused; retained for signature compatibility.

ParameterTypeDescription
$parametersarray``<``string``, ``mixed``>Matched parameters (modifiable for rewrite).
$legacyContainermixedUnused; retained for signature compatibility.

Returns bool``|WebResponse — false to reject the match on misconfiguration, otherwise a WebResponse carrying the redirect to be sent to the client.

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.
getContext()RoutingCallbackRetrieve the current application context.
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.
onGenerate()RoutingCallbackGets executed when the route of this callback is about to be reverse generated into an URL.
onNotMatched()RoutingCallbackExecuted when the route did NOT match (container-less).
removeParameter()ParameterHolderRemove a parameter.
reset()RoutingCallbackReturns the callback to its uninitialized state.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.