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