‪TYPO3CMS  9.5
FinisherVariableProvider.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
20 
28 final class ‪FinisherVariableProvider implements \ArrayAccess, \IteratorAggregate, \Countable
29 {
30 
37  protected ‪$objects = [];
38 
46  public function ‪add(string $finisherIdentifier, string $key, $value)
47  {
48  $this->‪addOrUpdate($finisherIdentifier, $key, $value);
49  }
50 
59  public function ‪addOrUpdate(string $finisherIdentifier, string $key, $value)
60  {
61  if (!array_key_exists($finisherIdentifier, $this->objects)) {
62  $this->objects[$finisherIdentifier] = [];
63  }
64  $this->objects[$finisherIdentifier] = ‪ArrayUtility::setValueByPath(
65  $this->objects[$finisherIdentifier],
66  $key,
67  $value,
68  '.'
69  );
70  }
71 
80  public function get(string $finisherIdentifier, string $key, $default = null)
81  {
82  if ($this->‪exists($finisherIdentifier, $key)) {
83  return ‪ArrayUtility::getValueByPath($this->objects[$finisherIdentifier], $key, '.');
84  }
85  return $default;
86  }
87 
95  public function ‪exists($finisherIdentifier, $key): bool
96  {
97  try {
98  ‪ArrayUtility::getValueByPath($this->objects[$finisherIdentifier], $key, '.');
99  } catch (‪MissingArrayPathException $e) {
100  return false;
101  }
102  return true;
103  }
104 
111  public function remove(string $finisherIdentifier, string $key)
112  {
113  if ($this->‪exists($finisherIdentifier, $key)) {
114  $this->objects[$finisherIdentifier] = ‪ArrayUtility::removeByPath(
115  $this->objects[$finisherIdentifier],
116  $key,
117  '.'
118  );
119  }
120  }
121 
127  public function ‪__sleep()
128  {
129  return ['objects'];
130  }
131 
139  public function ‪offsetExists($offset)
140  {
141  return isset($this->objects[$offset]);
142  }
143 
151  public function ‪offsetGet($offset)
152  {
153  return $this->objects[$offset];
154  }
155 
163  public function ‪offsetSet($offset, $value)
164  {
165  $this->objects[$offset] = $value;
166  }
167 
174  public function ‪offsetUnset($offset)
175  {
176  unset($this->objects[$offset]);
177  }
178 
182  public function ‪getIterator(): \Traversable
183  {
184  foreach ($this->objects as $offset => $value) {
185  yield $offset => $value;
186  }
187  }
188 
195  public function ‪count()
196  {
197  return ‪count($this->objects);
198  }
199 }
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetSet
‪offsetSet($offset, $value)
Definition: FinisherVariableProvider.php:162
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\add
‪add(string $finisherIdentifier, string $key, $value)
Definition: FinisherVariableProvider.php:45
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetExists
‪bool offsetExists($offset)
Definition: FinisherVariableProvider.php:138
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider
Definition: FinisherVariableProvider.php:29
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:26
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetUnset
‪offsetUnset($offset)
Definition: FinisherVariableProvider.php:173
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\addOrUpdate
‪addOrUpdate(string $finisherIdentifier, string $key, $value)
Definition: FinisherVariableProvider.php:58
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:3
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:179
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\__sleep
‪array __sleep()
Definition: FinisherVariableProvider.php:126
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetGet
‪mixed offsetGet($offset)
Definition: FinisherVariableProvider.php:150
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\getIterator
‪Traversable getIterator()
Definition: FinisherVariableProvider.php:181
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\exists
‪bool exists($finisherIdentifier, $key)
Definition: FinisherVariableProvider.php:94
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\count
‪int count()
Definition: FinisherVariableProvider.php:194
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeByPath
‪static array removeByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:311
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:271
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\$objects
‪array $objects
Definition: FinisherVariableProvider.php:36