TYPO3 CMS  TYPO3_7-6
ViewHelperVariableContainer.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
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, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
18 {
25  protected $objects = [];
26 
30  protected $view;
31 
45  public function add($viewHelperName, $key, $value)
46  {
47  if ($this->exists($viewHelperName, $key)) {
48  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException('The key "' . $viewHelperName . '->' . $key . '" was already stored and you cannot override it.', 1243352010);
49  }
50  $this->addOrUpdate($viewHelperName, $key, $value);
51  }
52 
63  public function addOrUpdate($viewHelperName, $key, $value)
64  {
65  if (!isset($this->objects[$viewHelperName])) {
66  $this->objects[$viewHelperName] = [];
67  }
68  $this->objects[$viewHelperName][$key] = $value;
69  }
70 
80  public function get($viewHelperName, $key)
81  {
82  if (!$this->exists($viewHelperName, $key)) {
83  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException('No value found for key "' . $viewHelperName . '->' . $key . '"', 1243325768);
84  }
85  return $this->objects[$viewHelperName][$key];
86  }
87 
96  public function exists($viewHelperName, $key)
97  {
98  return isset($this->objects[$viewHelperName]) && array_key_exists($key, $this->objects[$viewHelperName]);
99  }
100 
110  public function remove($viewHelperName, $key)
111  {
112  if (!$this->exists($viewHelperName, $key)) {
113  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException('No value found for key "' . $viewHelperName . '->' . $key . '", thus the key cannot be removed.', 1243352249);
114  }
115  unset($this->objects[$viewHelperName][$key]);
116  }
117 
124  public function setView(\TYPO3\CMS\Fluid\View\AbstractTemplateView $view)
125  {
126  $this->view = $view;
127  }
128 
136  public function getView()
137  {
138  return $this->view;
139  }
140 
146  public function __sleep()
147  {
148  return ['objects'];
149  }
150 }
setView(\TYPO3\CMS\Fluid\View\AbstractTemplateView $view)