‪TYPO3CMS  11.5
BackendUserConfiguration.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 
23 
30 {
34  protected ‪$backendUser;
35 
40  {
41  $this->backendUser = ‪$backendUser ?: ‪$GLOBALS['BE_USER'];
42  }
43 
50  public function get(string $key)
51  {
52  return (str_contains($key, '.')) ? $this->‪getFromDottedNotation($key) : $this->backendUser->uc[$key];
53  }
54 
60  public function ‪getAll()
61  {
62  return $this->backendUser->uc;
63  }
64 
71  public function set(string $key, $value): void
72  {
73  if (str_contains($key, '.')) {
74  $this->‪setFromDottedNotation($key, $value);
75  } else {
76  $this->backendUser->uc[$key] = $value;
77  }
78 
79  $this->backendUser->writeUC();
80  }
81 
89  public function ‪addToList(string $key, $value): void
90  {
91  $list = $this->get($key);
92 
93  if (!isset($list)) {
94  $list = $value;
95  } elseif (!GeneralUtility::inList($list, $value)) {
96  $list .= ',' . $value;
97  }
98 
99  $this->set($key, $list);
100  }
101 
109  public function ‪removeFromList(string $key, $value): void
110  {
111  $list = $this->get($key);
112 
113  if (GeneralUtility::inList($list, $value)) {
114  $list = ‪GeneralUtility::trimExplode(',', $list, true);
115  $list = ‪ArrayUtility::removeArrayEntryByValue($list, $value);
116  $this->set($key, implode(',', $list));
117  }
118  }
119 
123  public function ‪clear(): void
124  {
125  $this->backendUser->resetUC();
126  }
127 
133  public function ‪unsetOption(string $key): void
134  {
135  if (isset($this->backendUser->uc[$key])) {
136  unset($this->backendUser->uc[$key]);
137  $this->backendUser->writeUC();
138  }
139  }
140 
147  protected function ‪getFromDottedNotation(string $key)
148  {
149  $subkeys = ‪GeneralUtility::trimExplode('.', $key);
150  $configuration = $this->backendUser->uc;
151 
152  foreach ($subkeys as $subkey) {
153  if (isset($configuration[$subkey])) {
154  $configuration = &$configuration[$subkey];
155  } else {
156  $configuration = [];
157  break;
158  }
159  }
160 
161  return $configuration;
162  }
163 
170  protected function ‪setFromDottedNotation(string $key, $value): void
171  {
172  $subkeys = ‪GeneralUtility::trimExplode('.', $key, true);
173  $lastKey = $subkeys[count($subkeys) - 1];
174  $configuration = &$this->backendUser->uc;
175 
176  foreach ($subkeys as $subkey) {
177  if ($subkey === $lastKey) {
178  $configuration[$subkey] = $value;
179  } else {
180  $configuration = &$configuration[$subkey];
181  }
182  }
183  }
184 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\getFromDottedNotation
‪mixed getFromDottedNotation(string $key)
Definition: BackendUserConfiguration.php:146
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\setFromDottedNotation
‪setFromDottedNotation(string $key, $value)
Definition: BackendUserConfiguration.php:169
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration
Definition: BackendUserConfiguration.php:30
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\clear
‪clear()
Definition: BackendUserConfiguration.php:122
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeArrayEntryByValue
‪static array removeArrayEntryByValue(array $array, $cmpValue)
Definition: ArrayUtility.php:683
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\removeFromList
‪removeFromList(string $key, $value)
Definition: BackendUserConfiguration.php:108
‪TYPO3\CMS\Backend\Configuration
Definition: BackendUserConfiguration.php:18
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\getAll
‪mixed getAll()
Definition: BackendUserConfiguration.php:59
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\unsetOption
‪unsetOption(string $key)
Definition: BackendUserConfiguration.php:132
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\addToList
‪addToList(string $key, $value)
Definition: BackendUserConfiguration.php:88
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\$backendUser
‪BackendUserAuthentication $backendUser
Definition: BackendUserConfiguration.php:33
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\__construct
‪__construct(?BackendUserAuthentication $backendUser=null)
Definition: BackendUserConfiguration.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50