Skip to content

AbstractDispatcher

Generic PhalconKit dispatcher helper.

Native Phalcon 5.16 requires concrete dispatchers to implement the internal exception hooks used by the dispatch loop. MVC and CLI dispatchers keep their native specialized behavior; this generic wrapper provides a minimal concrete implementation so shared helper behavior can still be tested and used where no namespace-specific dispatcher is required.


Methods

handleException

Bubble user exceptions unchanged for the generic dispatcher wrapper.

protected handleException(\Exception $exception): never

Namespace-specific dispatchers can route exceptions through their dispatch:beforeException event flow, but this base helper has no controller/task domain to recover through.

Parameters:

Parameter Type Description
$exception \Exception Exception raised during dispatch.

Throws:

Always rethrows the original exception. - Exception


throwDispatchException

Raise a generic dispatcher exception for base-wrapper dispatch failures.

protected throwDispatchException(string $message, int $exceptionCode = 0): never

Parameters:

Parameter Type Description
$message string Diagnostic failure message.
$exceptionCode int Native dispatcher exception code.

Throws:

Always throws the generated dispatcher exception. - Exception


Inherited methods

getNamespaceName

Return the namespace currently targeted by the dispatcher.

public getNamespaceName(): ?string
  • This method is abstract.

getModuleName

Return the module currently targeted by the dispatcher.

public getModuleName(): ?string
  • This method is abstract.

setModuleName

Update the current module name before forwarding.

public setModuleName(?string $moduleName = null): void
  • This method is abstract. Parameters:
Parameter Type Description
$moduleName ?string

getActionName

Return the action currently targeted by the dispatcher.

public getActionName(): string
  • This method is abstract.

getParameters

Return current dispatch parameters.

public getParameters(): array<int|string,mixed>
  • This method is abstract.

getHandlerClass

Return the resolved controller or task class name.

public getHandlerClass(): string
  • This method is abstract.

getHandlerSuffix

Return the native handler suffix used by the dispatcher.

public getHandlerSuffix(): string
  • This method is abstract.

getActionSuffix

Return the native action suffix used by the dispatcher.

public getActionSuffix(): string
  • This method is abstract.

getActiveMethod

Return the concrete handler method name Phalcon will invoke.

public getActiveMethod(): string
  • This method is abstract.

callActionMethod

Invoke a controller or task action with positional parameters only.

public callActionMethod(mixed $handler, string $actionMethod, array<int|string,mixed> $params = []): mixed

Phalcon stores dispatch params as an array that may contain named metadata. Only integer-keyed entries are passed to action method arguments so route metadata cannot accidentally shift the method signature.

Parameters:

Parameter Type Description
$handler mixed Controller or task instance selected by Phalcon.
$actionMethod string Method name to call on the handler.
$params array Dispatch parameters.

Return Value:

Action return value.


forward

Forward to another target, optionally skipping cyclic forwards.

public forward(array<string,mixed> $forward, bool $preventCycle = false): void

Null forward parts are stripped before delegating to Phalcon. When $preventCycle is true, forwarding only happens if at least one target part differs from the current dispatch state.

Parameters:

Parameter Type Description
$forward array Forward target parts.
$preventCycle bool Whether identical forwards should be ignored.

canForward

Determine whether a forward target differs from the current dispatch.

public canForward(array<array-key,mixed> $forward): bool

Parameters:

Parameter Type Description
$forward array Forward target parts.

canForwardHandler

Determine whether the dispatcher-specific handler target changes.

private canForwardHandler(array<string,mixed> $forward): bool

MVC dispatchers compare controllers; CLI dispatchers compare tasks.

Parameters:

Parameter Type Description
$forward array Forward target parts.

canForwardController

Determine whether an MVC forward points to a different controller.

private canForwardController(?string $controller = null): bool

Parameters:

Parameter Type Description
$controller ?string

canForwardTask

Determine whether a CLI forward points to a different task.

private canForwardTask(?string $task = null): bool

Parameters:

Parameter Type Description
$task ?string

unsetForwardNullParts

Remove null parts from a forward target before delegating to Phalcon.

public unsetForwardNullParts(array<string,mixed> $forward, array<int,string>|null $parts = null): array<string,mixed>

Parameters:

Parameter Type Description
$forward array Forward target parts.
$parts array|null Forward keys to inspect. Defaults
to the common MVC and CLI target keys.

Return Value:

Forward target with null parts removed.


toArray

Export the active dispatcher state for diagnostics and debug responses.

public toArray(): array<string,mixed>

Return Value:

Current namespace, module, handler, action, parameters, and dispatcher-specific previous route state.