MessageController.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
14 
15 /**
16  * MessageController is used to get all messages translated to the given language.
17  *
18  * The controller supports the following actions:
19  *
20  * <div class="controller-action">
21  * <div> __Action__ _default_ </div>
22  * <div>
23  * Get all messages.
24  * | Parameter | Description
25  * |------------------------|-------------------------
26  * | _in_ `language` | The language
27  * | _out_ _message keys_ | Associative array of messages and their translations
28  * | __Response Actions__ | |
29  * | `ok` | In all cases
30  * </div>
31  * </div>
32  *
33  * @author ingo herwig <ingo@wemove.com>
34  */
36 
37  /**
38  * @see Controller::validate()
39  */
40  protected function validate() {
41  if (!$this->checkLanguageParameter()) {
42  return false;
43  }
44  // do default validation
45  return parent::validate();
46  }
47 
48  /**
49  * @see Controller::doExecute()
50  */
51  protected function doExecute($method=null) {
52 
53  $request = $this->getRequest();
54  $response = $this->getResponse();
55 
56  // get all messages
57  $lang = $request->getValue('language');
58  $messages = $this->getMessage()->getAll($lang);
59  $response->setValues($messages);
60 
61  // success
62  $response->setAction('ok');
63  }
64 
65  /**
66  * @see Controller::assignResponseDefaults()
67  */
68  protected function assignResponseDefaults() {
69  if (sizeof($this->getResponse()->getErrors()) > 0) {
70  parent::assignResponseDefaults();
71  }
72  // don't add anything in case of success
73  }
74 }
75 ?>
getMessage()
Get the Message instance.
Definition: Controller.php:315
getRequest()
Get the Request instance.
Definition: Controller.php:251
Application controllers.
Definition: namespaces.php:3
Controller is the base class of all controllers.
Definition: Controller.php:49
getResponse()
Get the Response instance.
Definition: Controller.php:259
checkLanguageParameter()
Checks the language request parameter and adds an response error, if it is not contained in the Local...
Definition: Controller.php:381
MessageController is used to get all messages translated to the given language.