‪TYPO3CMS  ‪main
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 {
38  protected ‪$objects = [];
39 
45  public function ‪add(string $finisherIdentifier, string $key, $value)
46  {
47  $this->‪addOrUpdate($finisherIdentifier, $key, $value);
48  }
49 
56  public function ‪addOrUpdate(string $finisherIdentifier, string $key, $value)
57  {
58  if (!array_key_exists($finisherIdentifier, $this->objects)) {
59  $this->objects[$finisherIdentifier] = [];
60  }
61  $this->objects[$finisherIdentifier] = ‪ArrayUtility::setValueByPath(
62  $this->objects[$finisherIdentifier],
63  $key,
64  $value,
65  '.'
66  );
67  }
68 
75  public function get(string $finisherIdentifier, string $key, $default = null)
76  {
77  if ($this->‪exists($finisherIdentifier, $key)) {
78  return ‪ArrayUtility::getValueByPath($this->objects[$finisherIdentifier], $key, '.');
79  }
80  return $default;
81  }
82 
89  public function ‪exists($finisherIdentifier, $key): bool
90  {
91  try {
92  ‪ArrayUtility::getValueByPath($this->objects[$finisherIdentifier] ?? [], $key, '.');
93  } catch (‪MissingArrayPathException $e) {
94  return false;
95  }
96  return true;
97  }
98 
102  public function remove(string $finisherIdentifier, string $key)
103  {
104  if ($this->‪exists($finisherIdentifier, $key)) {
105  $this->objects[$finisherIdentifier] = ‪ArrayUtility::removeByPath(
106  $this->objects[$finisherIdentifier],
107  $key,
108  '.'
109  );
110  }
111  }
112 
118  public function ‪__sleep()
119  {
120  return ['objects'];
121  }
122 
130  public function ‪offsetExists(mixed $offset): bool
131  {
132  return isset($this->objects[$offset]);
133  }
134 
142  public function ‪offsetGet(mixed $offset): mixed
143  {
144  return $this->objects[$offset];
145  }
146 
154  public function ‪offsetSet(mixed $offset, mixed $value): void
155  {
156  $this->objects[$offset] = $value;
157  }
158 
165  public function ‪offsetUnset(mixed $offset): void
166  {
167  unset($this->objects[$offset]);
168  }
169 
170  public function ‪getIterator(): \Traversable
171  {
172  foreach ($this->objects as $offset => $value) {
173  yield $offset => $value;
174  }
175  }
176 
183  public function ‪count(): int
184  {
185  return ‪count($this->objects);
186  }
187 }
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetGet
‪mixed offsetGet(mixed $offset)
Definition: FinisherVariableProvider.php:141
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\exists
‪exists($finisherIdentifier, $key)
Definition: FinisherVariableProvider.php:88
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetSet
‪offsetSet(mixed $offset, mixed $value)
Definition: FinisherVariableProvider.php:153
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeByPath
‪static array removeByPath(array $array, string $path, string $delimiter='/')
Definition: ArrayUtility.php:303
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\add
‪add(string $finisherIdentifier, string $key, $value)
Definition: FinisherVariableProvider.php:44
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider
Definition: FinisherVariableProvider.php:31
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:27
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\getIterator
‪getIterator()
Definition: FinisherVariableProvider.php:169
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\addOrUpdate
‪addOrUpdate(string $finisherIdentifier, string $key, $value)
Definition: FinisherVariableProvider.php:55
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static getValueByPath(array $array, array|string $path, string $delimiter='/')
Definition: ArrayUtility.php:176
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\__sleep
‪array __sleep()
Definition: FinisherVariableProvider.php:117
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\count
‪int count()
Definition: FinisherVariableProvider.php:182
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetUnset
‪offsetUnset(mixed $offset)
Definition: FinisherVariableProvider.php:164
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, string|array|\ArrayAccess $path, mixed $value, string $delimiter='/')
Definition: ArrayUtility.php:261
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\offsetExists
‪bool offsetExists(mixed $offset)
Definition: FinisherVariableProvider.php:129
‪TYPO3\CMS\Form\Domain\Finishers\FinisherVariableProvider\$objects
‪array $objects
Definition: FinisherVariableProvider.php:37