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)
 
 validateCsrfToken ($name)
 
 getLocalSessionValue ($key, $default=null)
 
 setLocalSessionValue ($key, $value)
 
 clearLocalSessionValues ()
 

Constructor & Destructor Documentation

__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 ( 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.

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.

Definition at line 123 of file Controller.php.

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 (   $method = null)
abstractprotected

Execute the given controller method.

Parameters
$methodThe name of the method to execute (optional)
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 207 of file Controller.php.

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 232 of file Controller.php.

getRequest ( )

Get the Request instance.

Returns
Request

Definition at line 247 of file Controller.php.

getResponse ( )

Get the Response instance.

Returns
Response

Definition at line 255 of file Controller.php.

getLogger ( )
protected

Get the Logger instance.

Returns
Logger

Definition at line 263 of file Controller.php.

getSession ( )
protected

Get the Session instance.

Returns
Session

Definition at line 271 of file Controller.php.

getPersistenceFacade ( )
protected

Get the PersistenceFacade instance.

Returns
PersistenceFacade

Definition at line 279 of file Controller.php.

getPermissionManager ( )
protected

Get the PermissionManager instance.

Returns
PermissionManager

Definition at line 287 of file Controller.php.

getActionMapper ( )
protected

Get the ActionMapper instance.

Returns
ActionMapper

Definition at line 295 of file Controller.php.

getLocalization ( )
protected

Get the Localization instance.

Returns
Localization

Definition at line 303 of file Controller.php.

getMessage ( )
protected

Get the Message instance.

Returns
Message

Definition at line 311 of file Controller.php.

getConfiguration ( )
protected

Get the Configuration instance.

Returns
Configuration

Definition at line 319 of file Controller.php.

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 330 of file Controller.php.

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 343 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 362 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 377 of file Controller.php.

generateCsrfToken (   $name)
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()

Definition at line 394 of file Controller.php.

validateCsrfToken (   $name)
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()
Returns
boolean

Definition at line 410 of file Controller.php.

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 431 of file Controller.php.

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 442 of file Controller.php.

clearLocalSessionValues ( )
protected

Remove all local session values.

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

Definition at line 457 of file Controller.php.

Member Data Documentation

const CSRF_TOKEN_PARAM = 'csrf_token'

Definition at line 51 of file Controller.php.