‪TYPO3CMS  ‪main
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 
70  public function set(string $key, $value): void
71  {
72  if (str_contains($key, '.')) {
73  $this->‪setFromDottedNotation($key, $value);
74  } else {
75  $this->backendUser->uc[$key] = $value;
76  }
77 
78  $this->backendUser->writeUC();
79  }
80 
87  public function ‪addToList(string $key, $value): void
88  {
89  $list = $this->get($key);
90 
91  if (!isset($list)) {
92  $list = $value;
93  } elseif (!‪GeneralUtility::inList($list, $value)) {
94  $list .= ',' . $value;
95  }
96 
97  $this->set($key, $list);
98  }
99 
106  public function ‪removeFromList(string $key, $value): void
107  {
108  $list = $this->get($key);
109 
110  if (‪GeneralUtility::inList($list, $value)) {
111  $list = ‪GeneralUtility::trimExplode(',', $list, true);
112  $list = ArrayUtility::removeArrayEntryByValue($list, $value);
113  $this->set($key, implode(',', $list));
114  }
115  }
116 
120  public function ‪clear(): void
121  {
122  $this->backendUser->resetUC();
123  }
124 
128  public function ‪unsetOption(string $key): void
129  {
130  if (isset($this->backendUser->uc[$key])) {
131  unset($this->backendUser->uc[$key]);
132  $this->backendUser->writeUC();
133  }
134  }
135 
142  protected function ‪getFromDottedNotation(string $key)
143  {
144  $subkeys = ‪GeneralUtility::trimExplode('.', $key);
145  $configuration = $this->backendUser->uc;
146 
147  foreach ($subkeys as $subkey) {
148  if (isset($configuration[$subkey])) {
149  $configuration = &$configuration[$subkey];
150  } else {
151  $configuration = [];
152  break;
153  }
154  }
155 
156  return $configuration;
157  }
158 
164  protected function ‪setFromDottedNotation(string $key, $value): void
165  {
166  $subkeys = ‪GeneralUtility::trimExplode('.', $key, true);
167  $lastKey = $subkeys[count($subkeys) - 1];
168  $configuration = &$this->backendUser->uc;
169 
170  foreach ($subkeys as $subkey) {
171  if ($subkey === $lastKey) {
172  $configuration[$subkey] = $value;
173  } else {
174  $configuration = &$configuration[$subkey];
175  }
176  }
177  }
178 }
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\__construct
‪__construct(BackendUserAuthentication $backendUser=null)
Definition: BackendUserConfiguration.php:38
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\getFromDottedNotation
‪mixed getFromDottedNotation(string $key)
Definition: BackendUserConfiguration.php:141
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\setFromDottedNotation
‪setFromDottedNotation(string $key, $value)
Definition: BackendUserConfiguration.php:163
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration
Definition: BackendUserConfiguration.php:30
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\clear
‪clear()
Definition: BackendUserConfiguration.php:119
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\removeFromList
‪removeFromList(string $key, $value)
Definition: BackendUserConfiguration.php:105
‪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:127
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\addToList
‪addToList(string $key, $value)
Definition: BackendUserConfiguration.php:86
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration\$backendUser
‪BackendUserAuthentication $backendUser
Definition: BackendUserConfiguration.php:33
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility\inList
‪static bool inList($list, $item)
Definition: GeneralUtility.php:422
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822