Skip to content

Phalcon dispatcher

NOTE

All classes are prefixed with Phalcon

Dispatcher\AbstractDispatcher Abstract

Source on GitHub

  • Namespace

    • Phalcon\Dispatcher
  • Uses

    • Exception
    • Phalcon\Di\AbstractInjectionAware
    • Phalcon\Di\DiInterface
    • Phalcon\Dispatcher\Exception
    • Phalcon\Events\EventsAwareInterface
    • Phalcon\Events\ManagerInterface
    • Phalcon\Filter\FilterInterface
    • Phalcon\Mvc\Model\Binder
    • Phalcon\Mvc\Model\BinderInterface
  • Extends

    AbstractInjectionAware

  • Implements

    • DispatcherInterface
    • EventsAwareInterface

This is the base class for Phalcon\Mvc\Dispatcher and Phalcon\Cli\Dispatcher. This class can't be instantiated directly, you can use it to create your own dispatchers.

Properties

/**
 * @var object|null
 */
protected $activeHandler;

/**
 * @var array
 */
protected $activeMethodMap;

/**
 * @var string
 */
protected $actionName = ;

/**
 * @var string
 */
protected $actionSuffix = Action;

/**
 * @var array
 */
protected $camelCaseMap;

/**
 * @var string
 */
protected $defaultAction = ;

/**
 * @var string
 */
protected $defaultNamespace = ;

/**
 * @var string
 */
protected $defaultHandler = ;

/**
 * @var array
 */
protected $handlerHashes;

/**
 * @var string
 */
protected $handlerName = ;

/**
 * @var string
 */
protected $handlerSuffix = ;

/**
 * @var ManagerInterface|null
 */
protected $eventsManager;

/**
 * @var bool
 */
protected $finished = false;

/**
 * @var bool
 */
protected $forwarded = false;

/**
 * @var bool
 */
protected $isControllerInitialize = false;

/**
 * @var mixed|null
 */
protected $lastHandler;

/**
 * @var BinderInterface|null
 */
protected $modelBinder;

/**
 * @var bool
 */
protected $modelBinding = false;

/**
 * @var string
 */
protected $moduleName = ;

/**
 * @var string
 */
protected $namespaceName = ;

/**
 * @var array
 */
protected $params;

/**
 * @var string|null
 */
protected $previousActionName = ;

/**
 * @var string|null
 */
protected $previousHandlerName = ;

/**
 * @var string|null
 */
protected $previousNamespaceName = ;

/**
 * @var string|null
 */
protected $returnedValue;

Methods

public function callActionMethod( mixed $handler, string $actionMethod, array $params = [] );

public function dispatch(): mixed | bool;
Process the results of the router by calling into the appropriate controller action(s) including any routing data or injected parameters.

public function forward( array $forward ): void;
Forwards the execution flow to another controller/action.

$this->dispatcher->forward(
    [
        "controller" => "posts",
        "action"     => "index",
    ]
);

@throws PhalconException

public function getActionName(): string;
Gets the latest dispatched action name

public function getActionSuffix(): string;
Gets the default action suffix

public function getActiveMethod(): string;
Returns the current method to be/executed in the dispatcher

public function getBoundModels(): array;
Returns bound models from binder instance

class UserController extends Controller
{
    public function showAction(User $user)
    {
        // return array with $user
        $boundModels = $this->dispatcher->getBoundModels();
    }
}

public function getDefaultNamespace(): string;
Returns the default namespace

public function getEventsManager(): ManagerInterface | null;
Returns the internal event manager

public function getHandlerClass(): string;
Possible class name that will be located to dispatch the request

public function getHandlerSuffix(): string;
Gets the default handler suffix

public function getModelBinder(): BinderInterface | null;
Gets model binder

public function getModuleName(): string | null;
Gets the module where the controller class is

public function getNamespaceName(): string;
Gets a namespace to be prepended to the current handler name

public function getParam( mixed $param, mixed $filters = null, mixed $defaultValue = null ): mixed;
Gets a param by its name or numeric index

public function getParameter( mixed $param, mixed $filters = null, mixed $defaultValue = null ): mixed;
Gets a param by its name or numeric index

public function getParameters(): array;
Gets action params

public function getParams(): array;
Gets action params

@todo remove this in future versions

public function getReturnedValue(): mixed;
Returns value returned by the latest dispatched action

public function hasParam( mixed $param ): bool;
Check if a param exists @todo deprecate this in the future

public function hasParameter( mixed $param ): bool;
Check if a param exists

public function isFinished(): bool;
Checks if the dispatch loop is finished or has more pendent controllers/tasks to dispatch

public function setActionName( string $actionName ): void;
Sets the action name to be dispatched

public function setActionSuffix( string $actionSuffix ): void;
Sets the default action suffix

public function setDefaultAction( string $actionName ): void;
Sets the default action name

public function setDefaultNamespace( string $defaultNamespace ): void;
Sets the default namespace

public function setEventsManager( ManagerInterface $eventsManager ): void;
Sets the events manager

public function setHandlerSuffix( string $handlerSuffix ): void;
Sets the default suffix for the handler

public function setModelBinder( BinderInterface $modelBinder, mixed $cache = null ): DispatcherInterface;
Enable model binding during dispatch

$di->set(
    'dispatcher',
    function() {
        $dispatcher = new Dispatcher();

        $dispatcher->setModelBinder(
            new Binder(),
            'cache'
        );

        return $dispatcher;
    }
);

public function setModuleName( string $moduleName = null ): void;
Sets the module where the controller is (only informative)

public function setNamespaceName( string $namespaceName ): void;
Sets the namespace where the controller class is

public function setParam( mixed $param, mixed $value ): void;
Set a param by its name or numeric index @todo deprecate this in the future

public function setParameter( mixed $param, mixed $value ): void;
Set a param by its name or numeric index

public function setParameters( array $params ): void;
Sets action params to be dispatched

public function setParams( array $params ): void;
Sets action params to be dispatched @todo deprecate this in the future

public function setReturnedValue( mixed $value ): void;
Sets the latest returned value by an action manually

public function wasForwarded(): bool;
Check if the current executed action was forwarded by another one

protected function resolveEmptyProperties(): void;
Set empty properties to their defaults (where defaults are available)

protected function toCamelCase( string $input ): string;

Dispatcher\DispatcherInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Dispatcher
  • Uses

  • Extends

  • Implements

Interface for Phalcon\Dispatcher\AbstractDispatcher

Methods

public function dispatch(): mixed | bool;
Dispatches a handle action taking into account the routing parameters

public function forward( array $forward ): void;
Forwards the execution flow to another controller/action

public function getActionName(): string;
Gets last dispatched action name

public function getActionSuffix(): string;
Gets the default action suffix

public function getHandlerSuffix(): string;
Gets the default handler suffix

public function getParam( mixed $param, mixed $filters = null ): mixed;
Gets a param by its name or numeric index

public function getParameter( mixed $param, mixed $filters = null ): mixed;
Gets a param by its name or numeric index

public function getParameters(): array;
Gets action params

public function getParams(): array;
Gets action params

public function getReturnedValue(): mixed;
Returns value returned by the latest dispatched action

public function hasParam( mixed $param ): bool;
Check if a param exists

public function isFinished(): bool;
Checks if the dispatch loop is finished or has more pendent controllers/tasks to dispatch

public function setActionName( string $actionName ): void;
Sets the action name to be dispatched

public function setActionSuffix( string $actionSuffix ): void;
Sets the default action suffix

public function setDefaultAction( string $actionName ): void;
Sets the default action name

public function setDefaultNamespace( string $defaultNamespace ): void;
Sets the default namespace

public function setHandlerSuffix( string $handlerSuffix ): void;
Sets the default suffix for the handler

public function setModuleName( string $moduleName = null ): void;
Sets the module name which the application belongs to

public function setNamespaceName( string $namespaceName ): void;
Sets the namespace which the controller belongs to

public function setParam( mixed $param, mixed $value ): void;
Set a param by its name or numeric index

public function setParams( array $params ): void;
Sets action params to be dispatched

Dispatcher\Exception

Source on GitHub

  • Namespace

    • Phalcon\Dispatcher
  • Uses

  • Extends

    \Exception

  • Implements

Exceptions thrown in Phalcon\Dispatcher/* will use this class

Constants

const EXCEPTION_ACTION_NOT_FOUND = 5;
const EXCEPTION_CYCLIC_ROUTING = 1;
const EXCEPTION_HANDLER_NOT_FOUND = 2;
const EXCEPTION_INVALID_HANDLER = 3;
const EXCEPTION_INVALID_PARAMS = 4;
const EXCEPTION_NO_DI = 0;