com\setasign\Konquadrat\Controller

ControllerDispatcher Class ControllerDispatcher

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

Class hierarchy

Summary

Constants

EVENT_CATCH_ERROR

public const \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\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

$application

protected \com\setasign\SetaFramework\Application\HttpApplicationInterface \com\setasign\SetaFramework\Controller\ControllerDispatcher::$application

$eventManager

protected \com\setasign\SetaFramework\EventManager\EventManager \com\setasign\SetaFramework\Controller\ControllerDispatcher::$eventManager

$initialized

protected array \com\setasign\SetaFramework\Controller\ControllerDispatcher::$initialized = array()

All already initialized controllers

$lastController

protected ?\com\setasign\SetaFramework\Controller\ControllerInterface \com\setasign\SetaFramework\Controller\ControllerDispatcher::$lastController

$response

protected ?\Psr\Http\Message\ResponseInterface \com\setasign\SetaFramework\Controller\ControllerDispatcher::$response

Methods

__construct()

public \com\setasign\SetaFramework\Controller\ControllerDispatcher::__construct (
\com\setasign\SetaFramework\Application\HttpApplicationInterface $application,
\com\setasign\SetaFramework\EventManager\EventManager $eventManager
)

ControllerDispatcher constructor.

Parameters
$application : \com\setasign\SetaFramework\Application\HttpApplicationInterface
 
$eventManager : \com\setasign\SetaFramework\EventManager\EventManager
 

call()

protected \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\InitControllerException If the controller cannot be initialized.

Throws \Throwable

cleanActionName()

protected \com\setasign\SetaFramework\Controller\ControllerDispatcher::cleanActionName (
string $actionName
): string
Parameters
$actionName : string
 

cleanControllerName()

protected \com\setasign\SetaFramework\Controller\ControllerDispatcher::cleanControllerName (
string $controllerName
): string
Parameters
$controllerName : string
 

dispatch()

public \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\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 \com\setasign\SetaFramework\Controller\ControllerDispatcher::getApplicationName (
void
): string

getController()

public \com\setasign\SetaFramework\Controller\ControllerDispatcher::getController (
string $controllerName,
array $params = array ( )
): \com\setasign\SetaFramework\Controller\ControllerInterface

Returns the instance of the controller.

Parameters
$controllerName : string

A controller name like Backend\Json\TestController

$params : array
 
Exceptions

Throws \com\setasign\SetaFramework\Controller\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()

public \com\setasign\SetaFramework\Controller\ControllerDispatcher::getLastController (
void
): ?\com\setasign\SetaFramework\Controller\ControllerInterface

Returns the last called controller

getResponse()

public \com\setasign\SetaFramework\Controller\ControllerDispatcher::getResponse (
void
): ?\Psr\Http\Message\ResponseInterface

initController()

protected \com\setasign\SetaFramework\Controller\ControllerDispatcher::initController (
string $controllerName
): \com\setasign\SetaFramework\Controller\ControllerInterface

Initializes a controller

Parameters
$controllerName : string

Full qualified classname

Exceptions

Throws \Throwable

setResponse()

public \com\setasign\SetaFramework\Controller\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