Detailed Description
Controller is the base class of all controllers.
Error Handling:
- throw an Exception or use response action failure to signal fatal errors (calls wcmf::application::controller::FailureController)
- add an ApplicationError to the response to signal non fatal errors (e.g. validation errors)
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 |
Definition at line 49 of file Controller.php.
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 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
-
$request Request 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. $response Response 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()
|
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
-
$method The name of the method to execute, will be passed to doExecute() (optional)
Definition at line 132 of file Controller.php.
◆ doExecute()
|
abstractprotected |
Execute the given controller method.
- Parameters
-
$method The name of the method to execute (optional)
Reimplemented in BatchController, PermissionController, SortController, SaveController, LoginController, ConcurrencyController, MultipleActionController, AssociateController, ListController, DisplayController, ValueListController, MediaController, DeleteController, SOAPController, MessageController, TreeController, AdminController, LoggingController, and FailureController.
◆ executeSubAction()
|
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
-
$action The name of the action to execute
- Returns
- Response instance
Definition at line 211 of file Controller.php.
◆ redirect()
|
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
-
$location The location to redirect to $key The key used as session variable name (optional) $data The data to be stored in the session (optional)
Definition at line 236 of file Controller.php.
◆ getRequest()
getRequest | ( | ) |
◆ getResponse()
getResponse | ( | ) |
◆ getLogger()
|
protected |
◆ getSession()
|
protected |
◆ getPersistenceFacade()
|
protected |
Get the PersistenceFacade instance.
- Returns
- PersistenceFacade
Definition at line 283 of file Controller.php.
◆ getPermissionManager()
|
protected |
Get the PermissionManager instance.
- Returns
- PermissionManager
Definition at line 291 of file Controller.php.
◆ getActionMapper()
|
protected |
◆ getLocalization()
|
protected |
◆ getMessage()
|
protected |
◆ getConfiguration()
|
protected |
◆ 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()
|
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
-
$commit Boolean whether the transaction should be committed
Definition at line 347 of file Controller.php.
◆ 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()
|
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()
|
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
-
$name The name of the token to be used in Controller::validateCsrfToken() $refresh Boolean indicating whether an existing token should be invalidated or reused (optional, default: true)
Definition at line 399 of file Controller.php.
◆ validateCsrfToken()
|
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
-
$name The name of the token as set in Controller::generateCsrfToken() $invalidate Boolean whether to delete the stored token or not (optional: default: true)
- Returns
- boolean
Definition at line 420 of file Controller.php.
◆ getLocalSessionValue()
|
protected |
Set the value of a local session variable.
- Parameters
-
$key The key (name) of the session vaiable. $default The 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()
|
protected |
Get the value of a local session variable.
- Parameters
-
$key The key (name) of the session vaiable. $value The value of the session variable.
Definition at line 454 of file Controller.php.
◆ clearLocalSessionValues()
|
protected |
Remove all local session values.
- Parameters
-
$key The key (name) of the session vaiable. $value The 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.