‪TYPO3CMS  10.4
FinisherVariableProvider.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
22 
30 final class ‪FinisherVariableProvider implements \ArrayAccess, \IteratorAggregate, \Countable
31 {
32 
39  protected ‪$objects = [];
40 
48  public function ‪add(string $finisherIdentifier, string $key, $value)
49  {
50  $this->‪addOrUpdate($finisherIdentifier, $key, $value);
51  }
52 
61  public function ‪addOrUpdate(string $finisherIdentifier, string $key, $value)
62  {
63  if (!array_key_exists($finisherIdentifier, $this->objects)) {
64  $this->objects[$finisherIdentifier] = [];
65  }
66  $this->objects[$finisherIdentifier] = ‪ArrayUtility::setValueByPath(
67  $this->objects[$finisherIdentifier],
68  $key,
69  $value,
70  '.'
71  );
72  }
73 
82  public function get(string $finisherIdentifier, string $key, $default = null)
83  {
84  if ($this->‪exists($finisherIdentifier, $key)) {
85  return ‪ArrayUtility::getValueByPath($this->objects[$finisherIdentifier], $key, '.');
86  }
87  return $default;
88  }
89 
97  public function ‪exists($finisherIdentifier, $key): bool
98  {
99  try {
100  ‪ArrayUtility::getValueByPath($this->objects[$finisherIdentifier] ?? [], $key, '.');
101  } catch (‪MissingArrayPathException $e) {
102  return false;
103  }
104  return true;
105  }
106 
113  public function remove(string $finisherIdentifier, string $key)
114  {
115  if ($this->‪exists($finisherIdentifier, $key)) {
116  $this->objects[$finisherIdentifier] = ‪ArrayUtility::removeByPath(
117  $this->objects[$finisherIdentifier],
118  $key,
119  '.'
120  );
121  }
122  }
123 
129  public function ‪__sleep()
130  {
131  return ['objects'];
132  }
133 
141  public function ‪offsetExists($offset)
142  {
143  return isset($this->objects[$offset]);
144  }
145 
153  public function ‪offsetGet($offset)
154  {
155  return $this->objects[$offset];
156  }
157 
165  public function ‪offsetSet($offset, $value)
166  {
167  $this->objects[$offset] = $value;
168  }
169 
176  public function ‪offsetUnset($offset)
177  {
178  unset($this->objects[$offset]);
179  }
180 
184  public function ‪getIterator(): \Traversable
185  {
186  foreach ($this->objects as $offset => $value) {
187  yield $offset => $value;
188  }
189  }
190 
197  public function ‪count()
198  {
199  return ‪count($this->objects);
200  }
201 }
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetSet
‪offsetSet($offset, $value)
Definition: FinisherVariableProvider.php:164
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\add
‪add(string $finisherIdentifier, string $key, $value)
Definition: FinisherVariableProvider.php:47
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetExists
‪bool offsetExists($offset)
Definition: FinisherVariableProvider.php:140
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider
Definition: FinisherVariableProvider.php:31
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:28
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetUnset
‪offsetUnset($offset)
Definition: FinisherVariableProvider.php:175
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\addOrUpdate
‪addOrUpdate(string $finisherIdentifier, string $key, $value)
Definition: FinisherVariableProvider.php:60
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:180
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\__sleep
‪array __sleep()
Definition: FinisherVariableProvider.php:128
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetGet
‪mixed offsetGet($offset)
Definition: FinisherVariableProvider.php:152
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\getIterator
‪Traversable getIterator()
Definition: FinisherVariableProvider.php:183
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\exists
‪bool exists($finisherIdentifier, $key)
Definition: FinisherVariableProvider.php:96
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\count
‪int count()
Definition: FinisherVariableProvider.php:196
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeByPath
‪static array removeByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:316
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:272
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\$objects
‪array $objects
Definition: FinisherVariableProvider.php:38