[!!!][TASK] Use correct ISO8601 format
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / View / AbstractView.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * An abstract View
19 *
20 * @api
21 */
22 abstract class AbstractView implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface
23 {
24 /**
25 * @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
26 * @api
27 */
28 protected $controllerContext;
29
30 /**
31 * View variables and their values
32 *
33 * @var array
34 * @see assign()
35 */
36 protected $variables = [];
37
38 /**
39 * Sets the current controller context
40 *
41 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
42 * @return void
43 */
44 public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
45 {
46 $this->controllerContext = $controllerContext;
47 }
48
49 /**
50 * Add a variable to $this->viewData.
51 * Can be chained, so $this->view->assign(..., ...)->assign(..., ...); is possible
52 *
53 * @param string $key Key of variable
54 * @param mixed $value Value of object
55 * @return \TYPO3\CMS\Extbase\Mvc\View\AbstractView an instance of $this, to enable chaining
56 * @api
57 */
58 public function assign($key, $value)
59 {
60 $this->variables[$key] = $value;
61 return $this;
62 }
63
64 /**
65 * Add multiple variables to $this->viewData.
66 *
67 * @param array $values array in the format array(key1 => value1, key2 => value2).
68 * @return \TYPO3\CMS\Extbase\Mvc\View\AbstractView an instance of $this, to enable chaining
69 * @api
70 */
71 public function assignMultiple(array $values)
72 {
73 foreach ($values as $key => $value) {
74 $this->assign($key, $value);
75 }
76 return $this;
77 }
78
79 /**
80 * Tells if the view implementation can render the view for the given context.
81 *
82 * By default we assume that the view implementation can handle all kinds of
83 * contexts. Override this method if that is not the case.
84 *
85 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
86 * @return bool TRUE if the view has something useful to display, otherwise FALSE
87 * @api
88 */
89 public function canRender(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
90 {
91 return true;
92 }
93
94 /**
95 * Initializes this view.
96 *
97 * Override this method for initializing your concrete view implementation.
98 *
99 * @return void
100 * @api
101 */
102 public function initializeView()
103 {
104 }
105 }