aea3cdc038eba35c9bbe39903f5fe9bf17102135
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / View / TX_EXTMVC_View_AbstractView.php
1 <?php
2 declare(ENCODING = 'utf-8');
3
4 /* *
5 * This script belongs to the FLOW3 framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/TX_EXTMVC_ViewInterface.php');
25
26 /**
27 * An abstract View
28 *
29 * @version $Id:$
30 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
31 */
32 abstract class TX_EXTMVC_View_AbstractView implements TX_EXTMVC_ViewInterface {
33
34 /**
35 * @var TX_EXTMVC_Request
36 */
37 protected $request;
38
39 /**
40 * @var array of TX_EXTMVC_View_Helper_HelperInterface
41 */
42 protected $viewHelpers;
43
44 /**
45 * @var array
46 */
47 protected $contextVariables = array();
48
49 /**
50 * Constructs the view.
51 */
52 public function __construct() {
53 }
54
55 /**
56 * Initializes the view after all dependencies have been injected
57 *
58 * @return void
59 * @author Robert Lemke <robert@typo3.org>
60 */
61 public function initializeObject() {
62 $this->initializeView();
63 }
64
65 /**
66 * Sets the current request
67 *
68 * @param TX_EXTMVC_Request $request
69 * @return void
70 * @author Robert Lemke <robert@typo3.org>
71 */
72 public function setRequest(TX_EXTMVC_Request $request) {
73 $this->request = $request;
74 }
75
76 /**
77 * Returns an View Helper instance.
78 * View Helpers must implement the interface TX_EXTMVC_View_Helper_HelperInterface
79 *
80 * @param string $viewHelperClassName the full name of the View Helper Class including
81 * @return TX_EXTMVC_View_Helper_HelperInterface The View Helper instance
82 * @author Bastian Waidelich <bastian@typo3.org>
83 */
84 public function getViewHelper($viewHelperClassName) {
85 if (!isset($this->viewHelpers[$viewHelperClassName])) {
86 $viewHelper = $this->objectManager->getObject($viewHelperClassName);
87 if (!$viewHelper instanceof TX_EXTMVC_View_Helper_HelperInterface) {
88 throw new TX_EXTMVC_Exception_InvalidViewHelper('View Helpers must implement interface "TX_EXTMVC_View_Helper_HelperInterface"', 1222895456);
89 }
90 $viewHelper->setRequest($this->request);
91 $this->viewHelpers[$viewHelperClassName] = $viewHelper;
92 }
93 return $this->viewHelpers[$viewHelperClassName];
94 }
95
96 /**
97 * Initializes this view.
98 *
99 * Override this method for initializing your concrete view implementation.
100 *
101 * @return void
102 */
103 protected function initializeView() {
104 }
105
106 /**
107 * Assigns domain models (single objects or aggregates) or values to the view
108 *
109 * @param string $valueName The name of the value
110 * @param mixed $value the value to assign
111 * @return void
112 */
113 public function assign($key, $value) {
114 $this->contextVariables[strtolower($key)] = $value;
115 }
116
117 }
118
119 ?>