‪TYPO3CMS  10.4
ServiceProvider.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 
18 namespace ‪TYPO3\CMS\Core;
19 
20 use ArrayObject;
21 use Psr\Container\ContainerInterface;
22 use Psr\EventDispatcher\EventDispatcherInterface;
23 use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
26 use TYPO3\SymfonyPsrEventDispatcherAdapter\EventDispatcherAdapter as SymfonyEventDispatcher;
27 
32 {
33  protected static function ‪getPackagePath(): string
34  {
35  return __DIR__ . '/../';
36  }
37 
38  public function ‪getFactories(): array
39  {
40  return [
41  SymfonyEventDispatcher::class => [ static::class, 'getSymfonyEventDispatcher' ],
42  Cache\CacheManager::class => [ static::class, 'getCacheManager' ],
43  Charset\CharsetConverter::class => [ static::class, 'getCharsetConverter' ],
44  Configuration\SiteConfiguration::class => [ static::class, 'getSiteConfiguration' ],
45  Console\CommandApplication::class => [ static::class, 'getConsoleCommandApplication' ],
46  Console\CommandRegistry::class => [ static::class, 'getConsoleCommandRegistry' ],
47  Context\Context::class => [ static::class, 'getContext' ],
48  Crypto\PasswordHashing\PasswordHashFactory::class => [ static::class, 'getPasswordHashFactory' ],
49  EventDispatcher\EventDispatcher::class => [ static::class, 'getEventDispatcher' ],
50  EventDispatcher\ListenerProvider::class => [ static::class, 'getEventListenerProvider' ],
51  Http\MiddlewareStackResolver::class => [ static::class, 'getMiddlewareStackResolver' ],
52  Http\RequestFactory::class => [ static::class, 'getRequestFactory' ],
53  Imaging\IconFactory::class => [ static::class, 'getIconFactory' ],
54  Imaging\IconRegistry::class => [ static::class, 'getIconRegistry' ],
55  Localization\LanguageServiceFactory::class => [ static::class, 'getLanguageServiceFactory' ],
56  Localization\LanguageStore::class => [ static::class, 'getLanguageStore' ],
57  Localization\Locales::class => [ static::class, 'getLocales' ],
58  Localization\LocalizationFactory::class => [ static::class, 'getLocalizationFactory' ],
59  Mail\TransportFactory::class => [ static::class, 'getMailTransportFactory' ],
60  Messaging\FlashMessageService::class => [ static::class, 'getFlashMessageService' ],
61  Package\FailsafePackageManager::class => [ static::class, 'getFailsafePackageManager' ],
62  Registry::class => [ static::class, 'getRegistry' ],
63  Resource\Index\FileIndexRepository::class => [ static::class, 'getFileIndexRepository' ],
64  Resource\Index\MetaDataRepository::class => [ static::class, 'getMetaDataRepository' ],
65  Resource\Driver\DriverRegistry::class => [ static::class, 'getDriverRegistry' ],
66  Resource\ProcessedFileRepository::class => [ static::class, 'getProcessedFileRepository' ],
67  Resource\ResourceFactory::class => [ static::class, 'getResourceFactory' ],
68  Resource\StorageRepository::class => [ static::class, 'getStorageRepository' ],
69  Service\DependencyOrderingService::class => [ static::class, 'getDependencyOrderingService' ],
70  Service\FlexFormService::class => [ static::class, 'getFlexFormService' ],
71  Service\OpcodeCacheService::class => [ static::class, 'getOpcodeCacheService' ],
72  TimeTracker\TimeTracker::class => [ static::class, 'getTimeTracker' ],
73  TypoScript\Parser\ConstantConfigurationParser::class => [ static::class, 'getTypoScriptConstantConfigurationParser' ],
74  TypoScript\TypoScriptService::class => [ static::class, 'getTypoScriptService' ],
75  'middlewares' => [ static::class, 'getMiddlewares' ],
76  ];
77  }
78 
79  public function ‪getExtensions(): array
80  {
81  return [
82  EventDispatcherInterface::class => [ static::class, 'provideFallbackEventDispatcher' ],
83  EventDispatcher\ListenerProvider::class => [ static::class, 'extendEventListenerProvider' ],
84  ] + parent::getExtensions();
85  }
86 
87  public static function ‪getSymfonyEventDispatcher(ContainerInterface $container): SymfonyEventDispatcherInterface
88  {
89  return ‪self::new($container, SymfonyEventDispatcher::class, [
90  $container->get(EventDispatcherInterface::class)
91  ]);
92  }
93 
94  public static function ‪getCacheManager(ContainerInterface $container): Cache\CacheManager
95  {
96  if (!$container->get('boot.state')->done) {
97  throw new \LogicException(Cache\CacheManager::class . ' can not be injected/instantiated during ext_localconf.php loading. Use lazy loading instead.', 1549446998);
98  }
99 
100  $cacheConfigurations = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] ?? [];
101  $disableCaching = $container->get('boot.state')->cacheDisabled;
102  $defaultCaches = [
103  $container->get('cache.core'),
104  $container->get('cache.assets'),
105  $container->get('cache.di'),
106  ];
107 
108  $cacheManager = ‪self::new($container, Cache\CacheManager::class, [$disableCaching]);
109  $cacheManager->setCacheConfigurations($cacheConfigurations);
110  $cacheConfigurations['di']['groups'] = ['system'];
111  foreach ($defaultCaches as $cache) {
112  $cacheManager->registerCache($cache, $cacheConfigurations[$cache->getIdentifier()]['groups'] ?? ['all']);
113  }
114 
115  return $cacheManager;
116  }
117 
118  public static function ‪getCharsetConverter(ContainerInterface $container): Charset\CharsetConverter
119  {
120  return ‪self::new($container, Charset\CharsetConverter::class);
121  }
122 
123  public static function ‪getSiteConfiguration(ContainerInterface $container): Configuration\SiteConfiguration
124  {
125  return ‪self::new($container, Configuration\SiteConfiguration::class, [‪Environment::getConfigPath() . '/sites']);
126  }
127 
128  public static function ‪getConsoleCommandApplication(ContainerInterface $container): Console\CommandApplication
129  {
131  $container->get(Context\Context::class),
132  $container->get(Console\CommandRegistry::class)
133  );
134  }
135 
136  public static function ‪getConsoleCommandRegistry(ContainerInterface $container): Console\CommandRegistry
137  {
138  return new ‪Console\CommandRegistry($container->get(Package\PackageManager::class), $container);
139  }
140 
141  public static function ‪getEventDispatcher(ContainerInterface $container): EventDispatcher\EventDispatcher
142  {
144  $container->get(EventDispatcher\ListenerProvider::class)
145  );
146  }
147 
148  public static function ‪getEventListenerProvider(ContainerInterface $container): EventDispatcher\ListenerProvider
149  {
150  return new ‪EventDispatcher\ListenerProvider($container);
151  }
152 
153  public static function ‪extendEventListenerProvider(
154  ContainerInterface $container,
155  EventDispatcher\ListenerProvider $listenerProvider
156  ): EventDispatcher\ListenerProvider {
157  $listenerProvider->addListener(
158  Package\Event\PackagesMayHaveChangedEvent::class,
159  Package\PackageManager::class,
160  'packagesMayHaveChanged'
161  );
162  return $listenerProvider;
163  }
164 
165  public static function ‪getContext(ContainerInterface $container): Context\Context
166  {
167  return new ‪Context\Context();
168  }
169 
170  public static function ‪getPasswordHashFactory(ContainerInterface $container): Crypto\PasswordHashing\PasswordHashFactory
171  {
173  }
174 
175  public static function ‪getIconFactory(ContainerInterface $container): Imaging\IconFactory
176  {
177  return ‪self::new($container, Imaging\IconFactory::class, [
178  $container->get(EventDispatcherInterface::class),
179  $container->get(Imaging\IconRegistry::class)
180  ]);
181  }
182 
183  public static function ‪getIconRegistry(ContainerInterface $container): Imaging\IconRegistry
184  {
185  return ‪self::new($container, Imaging\IconRegistry::class);
186  }
187 
188  public static function ‪getLanguageServiceFactory(ContainerInterface $container): Localization\LanguageServiceFactory
189  {
190  return ‪self::new($container, Localization\LanguageServiceFactory::class, [
191  $container->get(Localization\Locales::class),
192  $container->get(Localization\LocalizationFactory::class)
193  ]);
194  }
195 
196  public static function ‪getLanguageStore(ContainerInterface $container): Localization\LanguageStore
197  {
198  return ‪self::new($container, Localization\LanguageStore::class);
199  }
200 
201  public static function ‪getLocales(ContainerInterface $container): Localization\Locales
202  {
203  return ‪self::new($container, Localization\Locales::class);
204  }
205 
206  public static function ‪getLocalizationFactory(ContainerInterface $container): Localization\LocalizationFactory
207  {
208  return ‪self::new($container, Localization\LocalizationFactory::class, [
209  $container->get(Localization\LanguageStore::class),
210  $container->get(Cache\CacheManager::class)
211  ]);
212  }
213 
214  public static function ‪getMailTransportFactory(ContainerInterface $container): Mail\TransportFactory
215  {
216  return ‪self::new($container, Mail\TransportFactory::class, [
217  $container->get(SymfonyEventDispatcher::class),
218  $container->get(Log\LogManager::class)
219  ]);
220  }
221 
222  public static function ‪getFlashMessageService(ContainerInterface $container): Messaging\FlashMessageService
223  {
224  return ‪self::new($container, Messaging\FlashMessageService::class);
225  }
226 
227  public static function ‪getFailsafePackageManager(ContainerInterface $container): Package\FailsafePackageManager
228  {
229  $packageManager = $container->get(Package\PackageManager::class);
230  if ($packageManager instanceof Package\FailsafePackageManager) {
231  return $packageManager;
232  }
233  throw new \RuntimeException('FailsafePackageManager can only be instantiated in failsafe (maintenance tool) mode.', 1586861816);
234  }
235 
236  public static function ‪getRegistry(ContainerInterface $container): ‪Registry
237  {
238  return ‪self::new($container, Registry::class);
239  }
240 
241  public static function ‪getFileIndexRepository(ContainerInterface $container): Resource\Index\FileIndexRepository
242  {
243  return ‪self::new($container, Resource\Index\FileIndexRepository::class, [
244  $container->get(EventDispatcherInterface::class)
245  ]);
246  }
247 
248  public static function ‪getMetaDataRepository(ContainerInterface $container): Resource\Index\MetaDataRepository
249  {
250  return ‪self::new($container, Resource\Index\MetaDataRepository::class, [
251  $container->get(EventDispatcherInterface::class)
252  ]);
253  }
254 
255  public static function ‪getDriverRegistry(ContainerInterface $container): Resource\Driver\DriverRegistry
256  {
257  return ‪self::new($container, Resource\Driver\DriverRegistry::class);
258  }
259 
260  public static function ‪getProcessedFileRepository(ContainerInterface $container): Resource\ProcessedFileRepository
261  {
262  return ‪self::new($container, Resource\ProcessedFileRepository::class);
263  }
264 
265  public static function ‪getResourceFactory(ContainerInterface $container): Resource\ResourceFactory
266  {
267  return ‪self::new($container, Resource\ResourceFactory::class, [
268  $container->get(EventDispatcherInterface::class)
269  ]);
270  }
271 
272  public static function ‪getStorageRepository(ContainerInterface $container): Resource\StorageRepository
273  {
274  return ‪self::new($container, Resource\StorageRepository::class);
275  }
276 
277  public static function ‪getDependencyOrderingService(ContainerInterface $container): Service\DependencyOrderingService
278  {
279  return new Service\DependencyOrderingService();
280  }
281 
282  public static function ‪getFlexFormService(ContainerInterface $container): Service\FlexFormService
283  {
284  return ‪self::new($container, Service\FlexFormService::class);
285  }
286 
287  public static function ‪getOpcodeCacheService(ContainerInterface $container): Service\OpcodeCacheService
288  {
289  return ‪self::new($container, Service\OpcodeCacheService::class);
290  }
291 
292  public static function ‪getTimeTracker(ContainerInterface $container): TimeTracker\TimeTracker
293  {
294  return ‪self::new($container, TimeTracker\TimeTracker::class);
295  }
296 
297  public static function ‪getTypoScriptConstantConfigurationParser(ContainerInterface $container): TypoScript\Parser\ConstantConfigurationParser
298  {
299  return ‪self::new($container, TypoScript\Parser\ConstantConfigurationParser::class);
300  }
301 
302  public static function ‪getTypoScriptService(ContainerInterface $container): TypoScript\TypoScriptService
303  {
304  return ‪self::new($container, TypoScript\TypoScriptService::class);
305  }
306 
307  public static function ‪getRequestFactory(ContainerInterface $container): Http\RequestFactory
308  {
309  return new ‪Http\RequestFactory();
310  }
311 
312  public static function ‪getMiddlewareStackResolver(ContainerInterface $container): Http\MiddlewareStackResolver
313  {
315  $container,
316  $container->get(Service\DependencyOrderingService::class),
317  $container->get('cache.core')
318  );
319  }
320 
321  public static function ‪getMiddlewares(ContainerInterface $container): ArrayObject
322  {
323  return new ArrayObject();
324  }
325 
326  public static function ‪provideFallbackEventDispatcher(
327  ContainerInterface $container,
328  EventDispatcherInterface $eventDispatcher = null
329  ): EventDispatcherInterface {
330  // Provide a dummy / empty event dispatcher for the install tool when $eventDispatcher is null (that means when we run without symfony DI)
331  return $eventDispatcher ?? new ‪EventDispatcher\EventDispatcher(
332  new EventDispatcher\ListenerProvider($container)
333  );
334  }
335 }
‪TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory
Definition: PasswordHashFactory.php:27
‪TYPO3\CMS\Core\Package\AbstractServiceProvider
Definition: AbstractServiceProvider.php:31
‪TYPO3\CMS\Core\ServiceProvider\getFlexFormService
‪static getFlexFormService(ContainerInterface $container)
Definition: ServiceProvider.php:282
‪TYPO3\CMS\Core\ServiceProvider\getOpcodeCacheService
‪static getOpcodeCacheService(ContainerInterface $container)
Definition: ServiceProvider.php:287
‪TYPO3\CMS\Core\ServiceProvider\getMiddlewareStackResolver
‪static getMiddlewareStackResolver(ContainerInterface $container)
Definition: ServiceProvider.php:312
‪TYPO3\CMS\Core\ServiceProvider\getFailsafePackageManager
‪static getFailsafePackageManager(ContainerInterface $container)
Definition: ServiceProvider.php:227
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Core\Http\MiddlewareStackResolver
Definition: MiddlewareStackResolver.php:33
‪TYPO3\CMS\Core\ServiceProvider\getConsoleCommandRegistry
‪static getConsoleCommandRegistry(ContainerInterface $container)
Definition: ServiceProvider.php:136
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\new
‪static mixed new(ContainerInterface $container, string $className, array $constructorArguments=[])
Definition: AbstractServiceProvider.php:116
‪TYPO3\CMS\Core\ServiceProvider\getDependencyOrderingService
‪static getDependencyOrderingService(ContainerInterface $container)
Definition: ServiceProvider.php:277
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\ServiceProvider\getTimeTracker
‪static getTimeTracker(ContainerInterface $container)
Definition: ServiceProvider.php:292
‪TYPO3\CMS\Core\Console\CommandApplication
Definition: CommandApplication.php:39
‪TYPO3\CMS\Core\ServiceProvider\getDriverRegistry
‪static getDriverRegistry(ContainerInterface $container)
Definition: ServiceProvider.php:255
‪TYPO3\CMS\Core\Console\CommandRegistry
Definition: CommandRegistry.php:32
‪TYPO3\CMS\Core\ServiceProvider\getSiteConfiguration
‪static getSiteConfiguration(ContainerInterface $container)
Definition: ServiceProvider.php:123
‪TYPO3\CMS\Core\ServiceProvider\getProcessedFileRepository
‪static getProcessedFileRepository(ContainerInterface $container)
Definition: ServiceProvider.php:260
‪TYPO3\CMS\Core\ServiceProvider\getSymfonyEventDispatcher
‪static getSymfonyEventDispatcher(ContainerInterface $container)
Definition: ServiceProvider.php:87
‪TYPO3\CMS\Core\ServiceProvider\getPasswordHashFactory
‪static getPasswordHashFactory(ContainerInterface $container)
Definition: ServiceProvider.php:170
‪TYPO3\CMS\Core\ServiceProvider\getEventDispatcher
‪static getEventDispatcher(ContainerInterface $container)
Definition: ServiceProvider.php:141
‪TYPO3\CMS\Core\ServiceProvider\getIconFactory
‪static getIconFactory(ContainerInterface $container)
Definition: ServiceProvider.php:175
‪TYPO3\CMS\Core\EventDispatcher\EventDispatcher
Definition: EventDispatcher.php:30
‪TYPO3\CMS\Core\ServiceProvider\getIconRegistry
‪static getIconRegistry(ContainerInterface $container)
Definition: ServiceProvider.php:183
‪TYPO3\CMS\Core\ServiceProvider\getTypoScriptConstantConfigurationParser
‪static getTypoScriptConstantConfigurationParser(ContainerInterface $container)
Definition: ServiceProvider.php:297
‪TYPO3\CMS\Core\ServiceProvider\getLocales
‪static getLocales(ContainerInterface $container)
Definition: ServiceProvider.php:201
‪TYPO3\CMS\Core\ServiceProvider\getStorageRepository
‪static getStorageRepository(ContainerInterface $container)
Definition: ServiceProvider.php:272
‪TYPO3\CMS\Core\ServiceProvider
Definition: ServiceProvider.php:32
‪TYPO3\CMS\Core\ServiceProvider\getRegistry
‪static getRegistry(ContainerInterface $container)
Definition: ServiceProvider.php:236
‪TYPO3\CMS\Core\ServiceProvider\getCacheManager
‪static getCacheManager(ContainerInterface $container)
Definition: ServiceProvider.php:94
‪TYPO3\CMS\Core\ServiceProvider\getMailTransportFactory
‪static getMailTransportFactory(ContainerInterface $container)
Definition: ServiceProvider.php:214
‪TYPO3\CMS\Core\ServiceProvider\getConsoleCommandApplication
‪static getConsoleCommandApplication(ContainerInterface $container)
Definition: ServiceProvider.php:128
‪TYPO3\CMS\Core
‪TYPO3\CMS\Core\ServiceProvider\getFlashMessageService
‪static getFlashMessageService(ContainerInterface $container)
Definition: ServiceProvider.php:222
‪TYPO3\CMS\Core\ServiceProvider\getFactories
‪getFactories()
Definition: ServiceProvider.php:38
‪TYPO3\CMS\Core\ServiceProvider\getPackagePath
‪static getPackagePath()
Definition: ServiceProvider.php:33
‪TYPO3\CMS\Core\Http\RequestFactory
Definition: RequestFactory.php:31
‪TYPO3\CMS\Core\ServiceProvider\getCharsetConverter
‪static getCharsetConverter(ContainerInterface $container)
Definition: ServiceProvider.php:118
‪TYPO3\CMS\Core\ServiceProvider\getMiddlewares
‪static getMiddlewares(ContainerInterface $container)
Definition: ServiceProvider.php:321
‪TYPO3\CMS\Core\ServiceProvider\provideFallbackEventDispatcher
‪static provideFallbackEventDispatcher(ContainerInterface $container, EventDispatcherInterface $eventDispatcher=null)
Definition: ServiceProvider.php:326
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\ServiceProvider\getMetaDataRepository
‪static getMetaDataRepository(ContainerInterface $container)
Definition: ServiceProvider.php:248
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\ServiceProvider\getLanguageStore
‪static getLanguageStore(ContainerInterface $container)
Definition: ServiceProvider.php:196
‪TYPO3\CMS\Core\ServiceProvider\getTypoScriptService
‪static getTypoScriptService(ContainerInterface $container)
Definition: ServiceProvider.php:302
‪TYPO3\CMS\Core\ServiceProvider\getResourceFactory
‪static getResourceFactory(ContainerInterface $container)
Definition: ServiceProvider.php:265
‪TYPO3\CMS\Core\ServiceProvider\getExtensions
‪getExtensions()
Definition: ServiceProvider.php:79
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static string getConfigPath()
Definition: Environment.php:210
‪TYPO3\CMS\Core\ServiceProvider\getRequestFactory
‪static getRequestFactory(ContainerInterface $container)
Definition: ServiceProvider.php:307
‪TYPO3\CMS\Core\ServiceProvider\getEventListenerProvider
‪static getEventListenerProvider(ContainerInterface $container)
Definition: ServiceProvider.php:148
‪TYPO3\CMS\Core\ServiceProvider\extendEventListenerProvider
‪static extendEventListenerProvider(ContainerInterface $container, EventDispatcher\ListenerProvider $listenerProvider)
Definition: ServiceProvider.php:153
‪TYPO3\CMS\Core\ServiceProvider\getLocalizationFactory
‪static getLocalizationFactory(ContainerInterface $container)
Definition: ServiceProvider.php:206
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Core\ServiceProvider\getLanguageServiceFactory
‪static getLanguageServiceFactory(ContainerInterface $container)
Definition: ServiceProvider.php:188
‪TYPO3\CMS\Core\ServiceProvider\getContext
‪static getContext(ContainerInterface $container)
Definition: ServiceProvider.php:165
‪TYPO3\CMS\Core\ServiceProvider\getFileIndexRepository
‪static getFileIndexRepository(ContainerInterface $container)
Definition: ServiceProvider.php:241