com\setasign\SetaFramework\Controller

ControllerDispatcher Class ControllerDispatcher

File: /SetaFramework/src/Controller/ControllerDispatcher.php

Class hierarchy

Summary

Constants

EVENT_CATCH_ERROR

public const ControllerDispatcher::EVENT_CATCH_ERROR = 'application.run.catch_error'

Will be called when a application catched an error.


Note: All applications have the same eventManager. Listeners need to check whether the event is in the right application.
Type: ErrorEvent
Cancelable: If the event is canceled, the error will not be catched!
extraParams:
'applicationName' => string

EVENT_INIT_CONTROLLER

public const ControllerDispatcher::EVENT_INIT_CONTROLLER = 'application.init_controller'

Will be called when a controller will be initialized.


Note: All applications have the same eventManager. Listeners need to check whether the event is in the right application.
Type: ControllerDispatcherEvent
extraParams:
'applicationName' => string
'controllerName' => string

EVENT_POST_CALL

public const ControllerDispatcher::EVENT_POST_CALL = 'application.call.post'

Will be called after all actions are called.


Note: All applications have the same eventManager. Listeners need to check whether the event is in the right application.
Type: ControllerDispatcherEvent
extraParams:
'applicationName' => string
'controllerName' => string
'actionName' => string
'params' => array
'result' => &mixed

EVENT_POST_RUN

public const ControllerDispatcher::EVENT_POST_RUN = 'application.run.post'

Will be called after the application is finished. Also if there was an exception!

Listeners are able to change the response but not the View.


Note: All applications have the same eventManager. Listeners need to check whether the event is in the right application.
Type: ControllerDispatcherEvent
extraParams:
'applicationName' => string

EVENT_PRE_CALL

public const ControllerDispatcher::EVENT_PRE_CALL = 'application.call.pre'

Will be called before an action will be called and before the controller is initialized.


Note: All applications have the same eventManager. Listeners need to check whether the event is in the right application.
Type: ControllerDispatcherEvent
extraParams:
'applicationName' => string
'controllerName' => &string
'actionName' => &string
'params' => &array

EVENT_PRE_RUN

public const ControllerDispatcher::EVENT_PRE_RUN = 'application.run.pre'

Will be called when the run application is started.

Listeners are able to modify the routeData.


Note: All applications have the same eventManager. Listeners need to check whether the event is in the right application.
Type: ControllerDispatcherEvent
extraParams:
'applicationName' => string

Properties

$initialized

protected array ControllerDispatcher::$initialized = array()

All already initialized controllers

$response

protected ?\Psr\Http\Message\ResponseInterface ControllerDispatcher::$response

Methods

call()

protected ControllerDispatcher::call (
string $controllerName,
string $actionName,
array $params = array ( )
): ?mixed

Calls a action from a controller

If the controller isn't initialized so far initController will be called before.

Parameters
$controllerName : string
 
$actionName : string
 
$params : array
 
Exceptions

Throws InitControllerException If the controller cannot be initialized.

Throws \Throwable

cleanActionName()

protected ControllerDispatcher::cleanActionName (
string $actionName
): string
Parameters
$actionName : string
 

cleanControllerName()

protected ControllerDispatcher::cleanControllerName (
string $controllerName
): string
Parameters
$controllerName : string
 

dispatch()

public ControllerDispatcher::dispatch (
array $routeData
): ?mixed
Parameters
$routeData : array
 
Exceptions

Throws \Throwable If no errorHandler is defined, the error handler is invalid or the error handler throws an exception.

errorHandler()

protected ControllerDispatcher::errorHandler (
\Throwable $exception,
string $controllerName,
string $actionName,
array $params
): ?mixed
Parameters
$exception : \Throwable
 
$controllerName : string
 
$actionName : string
 
$params : array
 
Exceptions

Throws \Throwable If no errorHandler is defined, the error handler is invalid or the error handler throws an exception.

getApplicationName()

public ControllerDispatcher::getApplicationName (
void
): string

getController()

public ControllerDispatcher::getController (
string $controllerName,
array $params = array ( )
): ControllerInterface

Returns the instance of the controller.

Parameters
$controllerName : string

A controller name like Backend\Json\TestController

$params : array
 
Exceptions

Throws InitControllerException if an exception occurs on building the controller.

Throws \InvalidArgumentException if the controller name is invalid.

getControllerName()

protected ControllerDispatcher::getControllerName (
string $controllerName,
array $params = array ( )
): string

Get the full classname or an alias of the controller belongs to $controllerName

Parameters
$controllerName : string
 
$params : array
 

getLastController()

Returns the last called controller

getResponse()

public ControllerDispatcher::getResponse (
void
): ?\Psr\Http\Message\ResponseInterface

initController()

protected ControllerDispatcher::initController (
string $controllerName
): ControllerInterface

Initializes a controller

Parameters
$controllerName : string

Full qualified classname

Exceptions

Throws \Throwable

setResponse()

public ControllerDispatcher::setResponse (
\Psr\Http\Message\ResponseInterface $response
): void

This method can only be used in EVENT_POST_CALL and EVENT_POST_RUN

Parameters
$response : \Psr\Http\Message\ResponseInterface