‪TYPO3CMS  ‪main
GlobalVariableProvider.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 
20 use Psr\EventDispatcher\EventDispatcherInterface;
23 
25 {
29  protected array ‪$blindedConfigurationOptions = [
30  'TYPO3_CONF_VARS' => [
31  'BE' => [
32  'installToolPassword' => '******',
33  ],
34  'DB' => [
35  'database' => '******',
36  'host' => '******',
37  'password' => '******',
38  'port' => '******',
39  'socket' => '******',
40  'username' => '******',
41  'Connections' => [
42  'Default' => [
43  'dbname' => '******',
44  'host' => '******',
45  'password' => '******',
46  'port' => '******',
47  'user' => '******',
48  'unix_socket' => '******',
49  ],
50  ],
51  ],
52  'HTTP' => [
53  'cert' => '******',
54  'ssl_key' => '******',
55  ],
56  'MAIL' => [
57  'dsn' => '******',
58  'transport_smtp_encrypt' => '******',
59  'transport_smtp_password' => '******',
60  'transport_smtp_server' => '******',
61  'transport_smtp_username' => '******',
62  ],
63  'SYS' => [
64  'encryptionKey' => '******',
65  ],
66  ],
67  ];
68 
72  protected string ‪$globalVariableKey;
73 
74  public function ‪__construct(protected readonly EventDispatcherInterface $eventDispatcher) {}
75 
76  public function ‪__invoke(array $attributes): self
77  {
78  parent::__invoke($attributes);
79 
80  if (!($attributes['globalVariableKey'] ?? false)) {
81  throw new \RuntimeException('Attribute \'globalVariableKey\' must be set to use ' . __CLASS__, 1606478088);
82  }
83 
84  $this->globalVariableKey = $attributes['globalVariableKey'];
85  return $this;
86  }
87 
88  public function ‪getConfiguration(): array
89  {
90  $configurationArray = ‪$GLOBALS[‪$this->globalVariableKey] ?? [];
91  ‪$blindedConfigurationOptions = $this->eventDispatcher->dispatch(
92  new ‪ModifyBlindedConfigurationOptionsEvent($this->blindedConfigurationOptions, $this->identifier)
93  )->getBlindedConfigurationOptions();
94 
95  if (isset(‪$blindedConfigurationOptions[$this->globalVariableKey])) {
96  // Prepare blinding for all database connection types
97  foreach (array_keys(‪$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']) as $connectionName) {
98  if ($connectionName !== 'Default') {
99  ‪$blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections'][$connectionName] =
100  ‪$blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections']['Default'];
101  }
102  }
103  ArrayUtility::mergeRecursiveWithOverrule(
104  $configurationArray,
105  ArrayUtility::intersectRecursive(‪$blindedConfigurationOptions[$this->globalVariableKey], $configurationArray)
106  );
107  }
108  ArrayUtility::naturalKeySortRecursive($configurationArray);
109  return $configurationArray;
110  }
111 }
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider\getConfiguration
‪getConfiguration()
Definition: GlobalVariableProvider.php:88
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider\__invoke
‪__invoke(array $attributes)
Definition: GlobalVariableProvider.php:76
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider\__construct
‪__construct(protected readonly EventDispatcherInterface $eventDispatcher)
Definition: GlobalVariableProvider.php:74
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\AbstractProvider
Definition: AbstractProvider.php:27
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider\$blindedConfigurationOptions
‪array $blindedConfigurationOptions
Definition: GlobalVariableProvider.php:29
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider
Definition: AbstractProvider.php:18
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider\$globalVariableKey
‪string $globalVariableKey
Definition: GlobalVariableProvider.php:72
‪TYPO3\CMS\Lowlevel\ConfigurationModuleProvider\GlobalVariableProvider
Definition: GlobalVariableProvider.php:25
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Lowlevel\Event\ModifyBlindedConfigurationOptionsEvent
Definition: ModifyBlindedConfigurationOptionsEvent.php:25