TYPO3 CMS  TYPO3_6-2
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 = array();
26 
30  protected $view;
31 
45  public function add($viewHelperName, $key, $value) {
46  if ($this->exists($viewHelperName, $key)) {
47  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException('The key "' . $viewHelperName . '->' . $key . '" was already stored and you cannot override it.', 1243352010);
48  }
49  $this->addOrUpdate($viewHelperName, $key, $value);
50  }
51 
62  public function addOrUpdate($viewHelperName, $key, $value) {
63  if (!isset($this->objects[$viewHelperName])) {
64  $this->objects[$viewHelperName] = array();
65  }
66  $this->objects[$viewHelperName][$key] = $value;
67  }
68 
78  public function get($viewHelperName, $key) {
79  if (!$this->exists($viewHelperName, $key)) {
80  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException('No value found for key "' . $viewHelperName . '->' . $key . '"', 1243325768);
81  }
82  return $this->objects[$viewHelperName][$key];
83  }
84 
93  public function exists($viewHelperName, $key) {
94  return isset($this->objects[$viewHelperName][$key]);
95  }
96 
106  public function remove($viewHelperName, $key) {
107  if (!$this->exists($viewHelperName, $key)) {
108  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException('No value found for key "' . $viewHelperName . '->' . $key . '", thus the key cannot be removed.', 1243352249);
109  }
110  unset($this->objects[$viewHelperName][$key]);
111  }
112 
119  public function setView(\TYPO3\CMS\Fluid\View\AbstractTemplateView $view) {
120  $this->view = $view;
121  }
122 
130  public function getView() {
131  return $this->view;
132  }
133 
139  public function __sleep() {
140  return array('objects');
141  }
142 }
setView(\TYPO3\CMS\Fluid\View\AbstractTemplateView $view)