‪TYPO3CMS  ‪main
ConfigurationManager.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\Container\ContainerInterface;
21 use Psr\Http\Message\ServerRequestInterface;
24 
32 {
33  private ContainerInterface ‪$container;
34 
39 
40  private ?ServerRequestInterface ‪$request = null;
41 
42  public function ‪__construct(ContainerInterface ‪$container)
43  {
44  $this->container = ‪$container;
46  }
47 
48  protected function ‪initializeConcreteConfigurationManager(): void
49  {
50  // @todo: Move into getConfiguration() in v13.
51  // This will allow getting rid of $GLOBALS['TYPO3_REQUEST'] here, and the
52  // concrete ConfigurationManager is created "late" in getConfiguration().
53  // Check $this->concreteConfigurationManager for null. If null, fetch request from
54  // $this->request() (and *maybe* check TYPO3_REQUEST as b/w layer, better not), if still
55  // null, fall back to BackendConfigurationManager.
56  // Background: People tend to inject ConfigurationManager into non-extbase bootstrapped
57  // classes since the getConfiguration() API is so convenient. If request has not been set
58  // via setRequest(), this *may* indicate a CLI call. Extbase in general needs requests for
59  // controllers, but we *may* want to allow getting ConfigurationManager injected as
60  // "standalone" feature in CLI as well? OTOH, we could avoid this, when the TypoScript
61  // factories have been refactored far enough to be easily usable. If so, the request
62  // properties should be made non-nullable.
63  if ((‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
64  && ‪ApplicationType::fromRequest(‪$GLOBALS['TYPO3_REQUEST'])->isFrontend()
65  ) {
66  $this->concreteConfigurationManager = $this->container->get(FrontendConfigurationManager::class);
67  } else {
68  $this->concreteConfigurationManager = $this->container->get(BackendConfigurationManager::class);
69  }
70  }
71 
75  public function ‪setRequest(ServerRequestInterface ‪$request): void
76  {
77  $this->request = ‪$request;
78  // @todo: Move to getConfiguration() together with "late" creation of $this->concreteConfigurationManager
79  $this->concreteConfigurationManager->setRequest($this->request);
80  }
81 
89  public function ‪setConfiguration(array $configuration = []): void
90  {
91  // @todo: If really needed in v13 and if it can't be refactored out, park
92  // state in a property and $this->concreteConfigurationManager->setConfiguration()
93  // after concreteConfigurationManager has been created in getConfiguration().
94  $this->concreteConfigurationManager->setConfiguration($configuration);
95  }
96 
114  public function ‪getConfiguration(string $configurationType, string $extensionName = null, string $pluginName = null): array
115  {
116  switch ($configurationType) {
118  $configuration = $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
119  return $configuration['settings'] ?? [];
121  return $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
123  return $this->concreteConfigurationManager->getTypoScriptSetup();
124  default:
125  throw new ‪InvalidConfigurationTypeException('Invalid configuration type "' . $configurationType . '"', 1206031879);
126  }
127  }
128 }
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
Definition: BackendConfigurationManager.php:69
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\getConfiguration
‪array getConfiguration(string $configurationType, string $extensionName=null, string $pluginName=null)
Definition: ConfigurationManager.php:114
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\$concreteConfigurationManager
‪FrontendConfigurationManager BackendConfigurationManager $concreteConfigurationManager
Definition: ConfigurationManager.php:38
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FRAMEWORK
‪const CONFIGURATION_TYPE_FRAMEWORK
Definition: ConfigurationManagerInterface.php:29
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:32
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager
Definition: FrontendConfigurationManager.php:38
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\initializeConcreteConfigurationManager
‪initializeConcreteConfigurationManager()
Definition: ConfigurationManager.php:48
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\setConfiguration
‪setConfiguration(array $configuration=[])
Definition: ConfigurationManager.php:89
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\$request
‪ServerRequestInterface $request
Definition: ConfigurationManager.php:40
‪TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
Definition: InvalidConfigurationTypeException.php:25
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FULL_TYPOSCRIPT
‪const CONFIGURATION_TYPE_FULL_TYPOSCRIPT
Definition: ConfigurationManagerInterface.php:31
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_SETTINGS
‪const CONFIGURATION_TYPE_SETTINGS
Definition: ConfigurationManagerInterface.php:30
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\__construct
‪__construct(ContainerInterface $container)
Definition: ConfigurationManager.php:42
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\$container
‪ContainerInterface $container
Definition: ConfigurationManager.php:33
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\setRequest
‪setRequest(ServerRequestInterface $request)
Definition: ConfigurationManager.php:75
‪TYPO3\CMS\Core\Http\fromRequest
‪@ fromRequest
Definition: ApplicationType.php:66
‪TYPO3\CMS\Extbase\Configuration
Definition: BackendConfigurationManager.php:18
‪TYPO3\CMS\Core\Http\ApplicationType
‪ApplicationType
Definition: ApplicationType.php:55