[TASK] Streamline phpdoc annotations in EXT:extbase
[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 abstract class AbstractView implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface
21 {
22 /**
23 * @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
24 */
25 protected $controllerContext;
26
27 /**
28 * View variables and their values
29 *
30 * @var array
31 * @see assign()
32 */
33 protected $variables = [];
34
35 /**
36 * Sets the current controller context
37 *
38 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
39 */
40 public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
41 {
42 $this->controllerContext = $controllerContext;
43 }
44
45 /**
46 * Add a variable to $this->viewData.
47 * Can be chained, so $this->view->assign(..., ...)->assign(..., ...); is possible
48 *
49 * @param string $key Key of variable
50 * @param mixed $value Value of object
51 * @return \TYPO3\CMS\Extbase\Mvc\View\AbstractView an instance of $this, to enable chaining
52 */
53 public function assign($key, $value)
54 {
55 $this->variables[$key] = $value;
56 return $this;
57 }
58
59 /**
60 * Add multiple variables to $this->viewData.
61 *
62 * @param array $values array in the format array(key1 => value1, key2 => value2).
63 * @return \TYPO3\CMS\Extbase\Mvc\View\AbstractView an instance of $this, to enable chaining
64 */
65 public function assignMultiple(array $values)
66 {
67 foreach ($values as $key => $value) {
68 $this->assign($key, $value);
69 }
70 return $this;
71 }
72
73 /**
74 * Tells if the view implementation can render the view for the given context.
75 *
76 * By default we assume that the view implementation can handle all kinds of
77 * contexts. Override this method if that is not the case.
78 *
79 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
80 * @return bool TRUE if the view has something useful to display, otherwise FALSE
81 */
82 public function canRender(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
83 {
84 return true;
85 }
86
87 /**
88 * Initializes this view.
89 *
90 * Override this method for initializing your concrete view implementation.
91 */
92 public function initializeView()
93 {
94 }
95 }