Detailed Description

Controller is the base class of all controllers.

Error Handling:

The following default request/response parameters are defined:

Parameter Description
in / out action The action to be executed
in / out context The context of the action
in language The language of the requested data (optional)
out controller The name of the executed controller
out success Boolean whether the action completed successfully or not (depends on existence of error messages)
out errorMessage An error message which is displayed to the user
out errorCode An error code, describing the type of error
out errorData Some error codes require to transmit further information to the client
Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 49 of file Controller.php.

+ Inheritance diagram for Controller:

Public Member Functions

 __construct (Session $session, PersistenceFacade $persistenceFacade, PermissionManager $permissionManager, ActionMapper $actionMapper, Localization $localization, Message $message, Configuration $configuration)
 
 initialize (Request $request, Response $response)
 
 execute ($method=null)
 
 getRequest ()
 
 getResponse ()
 

Public Attributes

const CSRF_TOKEN_PARAM = 'csrf_token'
 

Protected Member Functions

 validate ()
 
 doExecute ($method=null)
 
 executeSubAction ($action)
 
 redirect ($location, $key=null, $data=null)
 
 getLogger ()
 
 getSession ()
 
 getPersistenceFacade ()
 
 getPermissionManager ()
 
 getActionMapper ()
 
 getLocalization ()
 
 getMessage ()
 
 getConfiguration ()
 
 requireTransaction ()
 
 endTransaction ($commit)
 
 isLocalizedRequest ()
 
 checkLanguageParameter ()
 
 generateCsrfToken ($name, $refresh=true)
 
 validateCsrfToken ($name, $invalidate=true)
 
 getLocalSessionValue ($key, $default=null)
 
 setLocalSessionValue ($key, $value)
 
 clearLocalSessionValues ()
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Session  $session,
PersistenceFacade  $persistenceFacade,
PermissionManager  $permissionManager,
ActionMapper  $actionMapper,
Localization  $localization,
Message  $message,
Configuration  $configuration 
)

Constructor.

Parameters
$session
$persistenceFacade
$permissionManager
$actionMapper
$localization
$message
$configuration

Definition at line 77 of file Controller.php.

Member Function Documentation

◆ initialize()

initialize ( Request  $request,
Response  $response 
)

Initialize the Controller with request/response data.

Which data is required is defined by the Controller. The base class method just stores the parameters in a member variable. Specialized Controllers may override this behavior for further initialization.

Attention
It lies in its responsibility to fail or do some default action if some data is missing.
Parameters
$requestRequest instance sent to the Controller. The sender attribute of the Request is the last controller's name, the context is the current context and the action is the requested one. All data sent from the last controller are accessible using the Request::getValue method. The request is supposed to be read-only. It will not be used any more after being passed to the controller.
$responseResponse instance that will be modified by the Controller. The initial values for context and action are the same as in the request parameter and are meant to be modified according to the performed action. The sender attribute of the response is set to the current controller. Initially there are no data stored in the response.

Reimplemented in CopyController, XMLExportController, RESTController, CSVImportController, BatchController, LoginController, SearchIndexController, CSVExportController, BatchDisplayController, and HistoryController.

Definition at line 108 of file Controller.php.

◆ validate()

validate ( )
protected

Check if the request is valid.

Subclasses will override this method to validate against their special requirements. Besides returning false, validation errors should be indicated by using the Response::addError method.

Returns
Boolean whether the data are ok or not.

Reimplemented in CopyController, CSVImportController, RESTController, SaveController, PermissionController, LoginController, ConcurrencyController, CSVExportController, BatchDisplayController, MultipleActionController, SearchController, SortController, AssociateController, ListController, HistoryController, DisplayController, ValueListController, DeleteController, and MessageController.

Definition at line 123 of file Controller.php.

◆ execute()

execute (   $method = null)

Execute the Controller resulting in its action processed.

The actual processing is delegated to the doExecute() method.

Parameters
$methodThe name of the method to execute, will be passed to doExecute() (optional)

Definition at line 132 of file Controller.php.

◆ doExecute()

◆ executeSubAction()

executeSubAction (   $action)
protected

Delegate the current request to another action.

The context is the same as the current context and the source controller will be set to this. The request and response format will be NullFormat which means that all request values should be passed in the application internal format and all response values will have that format. Execution will return to the calling controller instance afterwards.

Parameters
$actionThe name of the action to execute
Returns
Response instance

Definition at line 211 of file Controller.php.

◆ redirect()

redirect (   $location,
  $key = null,
  $data = null 
)
protected

Redirect to the given location with the given request data externally (HTTP status code 302).

The method will not return a result to the calling controller method. The calling method should return immediatly in order to avoid any side effects of code executed after the redirect. The given data are stored in the session under the given key.

Parameters
$locationThe location to redirect to
$keyThe key used as session variable name (optional)
$dataThe data to be stored in the session (optional)

Definition at line 236 of file Controller.php.

◆ getRequest()

getRequest ( )

Get the Request instance.

Returns
Request

Definition at line 251 of file Controller.php.

◆ getResponse()

getResponse ( )

Get the Response instance.

Returns
Response

Definition at line 259 of file Controller.php.

◆ getLogger()

getLogger ( )
protected

Get the Logger instance.

Returns
Logger

Definition at line 267 of file Controller.php.

◆ getSession()

getSession ( )
protected

Get the Session instance.

Returns
Session

Definition at line 275 of file Controller.php.

◆ getPersistenceFacade()

getPersistenceFacade ( )
protected

Get the PersistenceFacade instance.

Returns
PersistenceFacade

Definition at line 283 of file Controller.php.

◆ getPermissionManager()

getPermissionManager ( )
protected

Get the PermissionManager instance.

Returns
PermissionManager

Definition at line 291 of file Controller.php.

◆ getActionMapper()

getActionMapper ( )
protected

Get the ActionMapper instance.

Returns
ActionMapper

Definition at line 299 of file Controller.php.

◆ getLocalization()

getLocalization ( )
protected

Get the Localization instance.

Returns
Localization

Definition at line 307 of file Controller.php.

◆ getMessage()

getMessage ( )
protected

Get the Message instance.

Returns
Message

Definition at line 315 of file Controller.php.

◆ getConfiguration()

getConfiguration ( )
protected

Get the Configuration instance.

Returns
Configuration

Definition at line 323 of file Controller.php.

◆ requireTransaction()

requireTransaction ( )
protected

Start or join a transaction that will be committed at the end of execution.

If a transaction already is started it will be joined and committed by the controller that started it. This allows to compose actions by using the Controller::executeSubAction() method that all share the same transaction.

Returns
Boolean whether a new transaction was started or an existing was joined

Definition at line 334 of file Controller.php.

◆ endTransaction()

endTransaction (   $commit)
protected

End the transaction.

Only if this controller instance started the transaction, it will be committed or rolled back. Otherwise the call will be ignored.

Parameters
$commitBoolean whether the transaction should be committed

Definition at line 347 of file Controller.php.

◆ isLocalizedRequest()

isLocalizedRequest ( )
protected

Check if the current request is localized.

This is true, if it has a language parameter that is not equal to Localization::getDefaultLanguage(). Throws an exception if a language is given which is not supported

Returns
Boolean whether the request is localized or not

Definition at line 366 of file Controller.php.

◆ checkLanguageParameter()

checkLanguageParameter ( )
protected

Checks the language request parameter and adds an response error, if it is not contained in the Localization::getSupportedLanguages() list.

Returns
Boolean

Definition at line 381 of file Controller.php.

◆ generateCsrfToken()

generateCsrfToken (   $name,
  $refresh = true 
)
protected

Create a CSRF token, store it in the session and set it in the response.

The name of the response parameter is Controller::CSRF_TOKEN_PARAM.

Parameters
$nameThe name of the token to be used in Controller::validateCsrfToken()
$refreshBoolean indicating whether an existing token should be invalidated or reused (optional, default: true)

Definition at line 399 of file Controller.php.

◆ validateCsrfToken()

validateCsrfToken (   $name,
  $invalidate = true 
)
protected

Validate the CSRF token contained in the request against the token stored in the session.

The name of the request parameter is Controller::CSRF_TOKEN_PARAM.

Parameters
$nameThe name of the token as set in Controller::generateCsrfToken()
$invalidateBoolean whether to delete the stored token or not (optional: default: true)
Returns
boolean

Definition at line 420 of file Controller.php.

◆ getLocalSessionValue()

getLocalSessionValue (   $key,
  $default = null 
)
protected

Set the value of a local session variable.

Parameters
$keyThe key (name) of the session vaiable.
$defaultThe default value if the key is not defined (optional, default: null)
Returns
The session var or null if it doesn't exist.

Definition at line 443 of file Controller.php.

◆ setLocalSessionValue()

setLocalSessionValue (   $key,
  $value 
)
protected

Get the value of a local session variable.

Parameters
$keyThe key (name) of the session vaiable.
$valueThe value of the session variable.

Definition at line 454 of file Controller.php.

◆ clearLocalSessionValues()

clearLocalSessionValues ( )
protected

Remove all local session values.

Parameters
$keyThe key (name) of the session vaiable.
$valueThe value of the session variable.

Definition at line 469 of file Controller.php.

Member Data Documentation

◆ CSRF_TOKEN_PARAM

const CSRF_TOKEN_PARAM = 'csrf_token'

Definition at line 51 of file Controller.php.