1<?php
2
3/*
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16namespace TYPO3\CMS\Extbase\Mvc\View;
17
18use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
19
20/**
21 * An abstract View
22 * @deprecated since TYPO3 v11, will be removed in TYPO3 v12.0. It is highly recommended to implement all needed logic of ViewInterface yourself
23 */
24abstract class AbstractView implements ViewInterface
25{
26    /**
27     * @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
28     */
29    protected $controllerContext;
30
31    /**
32     * View variables and their values
33     *
34     * @var array
35     * @see assign()
36     */
37    protected $variables = [];
38
39    /**
40     * Sets the current controller context
41     *
42     * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
43     */
44    public function setControllerContext(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     */
57    public function assign($key, $value)
58    {
59        $this->variables[$key] = $value;
60        return $this;
61    }
62
63    /**
64     * Add multiple variables to $this->viewData.
65     *
66     * @param array $values array in the format array(key1 => value1, key2 => value2).
67     * @return \TYPO3\CMS\Extbase\Mvc\View\AbstractView an instance of $this, to enable chaining
68     */
69    public function assignMultiple(array $values)
70    {
71        foreach ($values as $key => $value) {
72            $this->assign($key, $value);
73        }
74        return $this;
75    }
76
77    /**
78     * Tells if the view implementation can render the view for the given context.
79     *
80     * By default we assume that the view implementation can handle all kinds of
81     * contexts. Override this method if that is not the case.
82     *
83     * @return bool TRUE if the view has something useful to display, otherwise FALSE
84     * @deprecated since TYPO3 v11, will be removed in v12. Legacy method, not part of ViewInterface anymore.
85     */
86    public function canRender()
87    {
88        trigger_error('Method ' . __METHOD__ . ' has been deprecated in v11 and will be removed with v12.', E_USER_DEPRECATED);
89        return true;
90    }
91
92    /**
93     * Initializes this view.
94     *
95     * Override this method for initializing your concrete view implementation.
96     */
97    public function initializeView()
98    {
99    }
100}
101