Completed
Push — master ( 62b2d3...36b4e3 )
by
unknown
17:26
created

ServiceProvider::getProcessedFileRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 TYPO3\CMS\Core\Core\Environment;
24
use TYPO3\CMS\Core\Package\AbstractServiceProvider;
25
26
/**
27
 * @internal
28
 */
29
class ServiceProvider extends AbstractServiceProvider
30
{
31
    protected static function getPackagePath(): string
32
    {
33
        return __DIR__ . '/../';
34
    }
35
36
    public function getFactories(): array
37
    {
38
        return [
39
            Cache\CacheManager::class => [ static::class, 'getCacheManager' ],
40
            Charset\CharsetConverter::class => [ static::class, 'getCharsetConverter' ],
41
            Configuration\SiteConfiguration::class => [ static::class, 'getSiteConfiguration' ],
42
            Console\CommandApplication::class => [ static::class, 'getConsoleCommandApplication' ],
43
            Console\CommandRegistry::class => [ static::class, 'getConsoleCommandRegistry' ],
44
            Context\Context::class => [ static::class, 'getContext' ],
45
            Crypto\PasswordHashing\PasswordHashFactory::class => [ static::class, 'getPasswordHashFactory' ],
46
            EventDispatcher\EventDispatcher::class => [ static::class, 'getEventDispatcher' ],
47
            EventDispatcher\ListenerProvider::class => [ static::class, 'getEventListenerProvider' ],
48
            Http\MiddlewareStackResolver::class => [ static::class, 'getMiddlewareStackResolver' ],
49
            Http\RequestFactory::class => [ static::class, 'getRequestFactory' ],
50
            Imaging\IconFactory::class => [ static::class, 'getIconFactory' ],
51
            Imaging\IconRegistry::class => [ static::class, 'getIconRegistry' ],
52
            Localization\LanguageServiceFactory::class => [ static::class, 'getLanguageServiceFactory' ],
53
            Localization\LanguageStore::class => [ static::class, 'getLanguageStore' ],
54
            Localization\Locales::class => [ static::class, 'getLocales' ],
55
            Localization\LocalizationFactory::class => [ static::class, 'getLocalizationFactory' ],
56
            Mail\TransportFactory::class => [ static::class, 'getMailTransportFactory' ],
57
            Messaging\FlashMessageService::class => [ static::class, 'getFlashMessageService' ],
58
            Package\FailsafePackageManager::class => [ static::class, 'getFailsafePackageManager' ],
59
            Registry::class => [ static::class, 'getRegistry' ],
60
            Resource\Index\FileIndexRepository::class => [ static::class, 'getFileIndexRepository' ],
61
            Resource\Index\MetaDataRepository::class => [ static::class, 'getMetaDataRepository' ],
62
            Resource\Driver\DriverRegistry::class => [ static::class, 'getDriverRegistry' ],
63
            Resource\ProcessedFileRepository::class => [ static::class, 'getProcessedFileRepository' ],
64
            Resource\ResourceFactory::class => [ static::class, 'getResourceFactory' ],
65
            Resource\StorageRepository::class => [ static::class, 'getStorageRepository' ],
66
            Service\DependencyOrderingService::class => [ static::class, 'getDependencyOrderingService' ],
67
            Service\FlexFormService::class => [ static::class, 'getFlexFormService' ],
68
            Service\OpcodeCacheService::class => [ static::class, 'getOpcodeCacheService' ],
69
            TimeTracker\TimeTracker::class => [ static::class, 'getTimeTracker' ],
70
            TypoScript\Parser\ConstantConfigurationParser::class => [ static::class, 'getTypoScriptConstantConfigurationParser' ],
71
            TypoScript\TypoScriptService::class => [ static::class, 'getTypoScriptService' ],
72
            'middlewares' => [ static::class, 'getMiddlewares' ],
73
        ];
74
    }
75
76
    public function getExtensions(): array
77
    {
78
        return [
79
            EventDispatcherInterface::class => [ static::class, 'provideFallbackEventDispatcher' ],
80
            EventDispatcher\ListenerProvider::class => [ static::class, 'extendEventListenerProvider' ],
81
        ] + parent::getExtensions();
82
    }
83
84
    public static function getCacheManager(ContainerInterface $container): Cache\CacheManager
85
    {
86
        if (!$container->get('boot.state')->done) {
87
            throw new \LogicException(Cache\CacheManager::class . ' can not be injected/instantiated during ext_localconf.php loading. Use lazy loading instead.', 1549446998);
88
        }
89
90
        $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] ?? [];
91
        $disableCaching = $container->get('boot.state')->cacheDisabled;
92
        $defaultCaches = [
93
            $container->get('cache.core'),
94
            $container->get('cache.assets'),
95
            $container->get('cache.di'),
96
        ];
97
98
        $cacheManager = self::new($container, Cache\CacheManager::class, [$disableCaching]);
99
        $cacheManager->setCacheConfigurations($cacheConfigurations);
100
        $cacheConfigurations['di']['groups'] = ['system'];
101
        foreach ($defaultCaches as $cache) {
102
            $cacheManager->registerCache($cache, $cacheConfigurations[$cache->getIdentifier()]['groups'] ?? ['all']);
103
        }
104
105
        return $cacheManager;
106
    }
107
108
    public static function getCharsetConverter(ContainerInterface $container): Charset\CharsetConverter
109
    {
110
        return self::new($container, Charset\CharsetConverter::class);
111
    }
112
113
    public static function getSiteConfiguration(ContainerInterface $container): Configuration\SiteConfiguration
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

113
    public static function getSiteConfiguration(/** @scrutinizer ignore-unused */ ContainerInterface $container): Configuration\SiteConfiguration

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
114
    {
115
        return new Configuration\SiteConfiguration(Environment::getConfigPath() . '/sites');
116
    }
117
118
    public static function getConsoleCommandApplication(ContainerInterface $container): Console\CommandApplication
119
    {
120
        return new Console\CommandApplication(
121
            $container->get(Context\Context::class),
122
            $container->get(Console\CommandRegistry::class)
123
        );
124
    }
125
126
    public static function getConsoleCommandRegistry(ContainerInterface $container): Console\CommandRegistry
127
    {
128
        return new Console\CommandRegistry($container->get(Package\PackageManager::class), $container);
129
    }
130
131
    public static function getEventDispatcher(ContainerInterface $container): EventDispatcher\EventDispatcher
132
    {
133
        return new EventDispatcher\EventDispatcher(
134
            $container->get(EventDispatcher\ListenerProvider::class)
135
        );
136
    }
137
138
    public static function getEventListenerProvider(ContainerInterface $container): EventDispatcher\ListenerProvider
139
    {
140
        return new EventDispatcher\ListenerProvider($container);
141
    }
142
143
    public static function extendEventListenerProvider(
144
        ContainerInterface $container,
145
        EventDispatcher\ListenerProvider $listenerProvider
146
    ): EventDispatcher\ListenerProvider {
147
        $listenerProvider->addListener(
148
            Package\Event\PackagesMayHaveChangedEvent::class,
149
            Package\PackageManager::class,
150
            'packagesMayHaveChanged'
151
        );
152
        return $listenerProvider;
153
    }
154
155
    public static function getContext(ContainerInterface $container): Context\Context
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

155
    public static function getContext(/** @scrutinizer ignore-unused */ ContainerInterface $container): Context\Context

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
156
    {
157
        return new Context\Context();
158
    }
159
160
    public static function getPasswordHashFactory(ContainerInterface $container): Crypto\PasswordHashing\PasswordHashFactory
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

160
    public static function getPasswordHashFactory(/** @scrutinizer ignore-unused */ ContainerInterface $container): Crypto\PasswordHashing\PasswordHashFactory

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
161
    {
162
        return new Crypto\PasswordHashing\PasswordHashFactory();
163
    }
164
165
    public static function getIconFactory(ContainerInterface $container): Imaging\IconFactory
166
    {
167
        return self::new($container, Imaging\IconFactory::class, [
168
            $container->get(EventDispatcherInterface::class),
169
            $container->get(Imaging\IconRegistry::class)
170
        ]);
171
    }
172
173
    public static function getIconRegistry(ContainerInterface $container): Imaging\IconRegistry
174
    {
175
        return self::new($container, Imaging\IconRegistry::class);
176
    }
177
178
    public static function getLanguageServiceFactory(ContainerInterface $container): Localization\LanguageServiceFactory
179
    {
180
        return self::new($container, Localization\LanguageServiceFactory::class, [
181
            $container->get(Localization\Locales::class),
182
            $container->get(Localization\LocalizationFactory::class)
183
        ]);
184
    }
185
186
    public static function getLanguageStore(ContainerInterface $container): Localization\LanguageStore
187
    {
188
        return self::new($container, Localization\LanguageStore::class);
189
    }
190
191
    public static function getLocales(ContainerInterface $container): Localization\Locales
192
    {
193
        return self::new($container, Localization\Locales::class);
194
    }
195
196
    public static function getLocalizationFactory(ContainerInterface $container): Localization\LocalizationFactory
197
    {
198
        return self::new($container, Localization\LocalizationFactory::class, [
199
            $container->get(Localization\LanguageStore::class),
200
            $container->get(Cache\CacheManager::class)
201
        ]);
202
    }
203
204
    public static function getMailTransportFactory(ContainerInterface $container): Mail\TransportFactory
205
    {
206
        return self::new($container, Mail\TransportFactory::class);
207
    }
208
209
    public static function getFlashMessageService(ContainerInterface $container): Messaging\FlashMessageService
210
    {
211
        return self::new($container, Messaging\FlashMessageService::class);
212
    }
213
214
    public static function getFailsafePackageManager(ContainerInterface $container): Package\FailsafePackageManager
215
    {
216
        $packageManager = $container->get(Package\PackageManager::class);
217
        if ($packageManager instanceof Package\FailsafePackageManager) {
218
            return $packageManager;
219
        }
220
        throw new \RuntimeException('FailsafePackageManager can only be instantiated in failsafe (maintenance tool) mode.', 1586861816);
221
    }
222
223
    public static function getRegistry(ContainerInterface $container): Registry
224
    {
225
        return self::new($container, Registry::class);
226
    }
227
228
    public static function getFileIndexRepository(ContainerInterface $container): Resource\Index\FileIndexRepository
229
    {
230
        return self::new($container, Resource\Index\FileIndexRepository::class, [
231
            $container->get(EventDispatcherInterface::class)
232
        ]);
233
    }
234
235
    public static function getMetaDataRepository(ContainerInterface $container): Resource\Index\MetaDataRepository
236
    {
237
        return self::new($container, Resource\Index\MetaDataRepository::class, [
238
            $container->get(EventDispatcherInterface::class)
239
        ]);
240
    }
241
242
    public static function getDriverRegistry(ContainerInterface $container): Resource\Driver\DriverRegistry
243
    {
244
        return self::new($container, Resource\Driver\DriverRegistry::class);
245
    }
246
247
    public static function getProcessedFileRepository(ContainerInterface $container): Resource\ProcessedFileRepository
248
    {
249
        return self::new($container, Resource\ProcessedFileRepository::class);
250
    }
251
252
    public static function getResourceFactory(ContainerInterface $container): Resource\ResourceFactory
253
    {
254
        return self::new($container, Resource\ResourceFactory::class, [
255
            $container->get(EventDispatcherInterface::class)
256
        ]);
257
    }
258
259
    public static function getStorageRepository(ContainerInterface $container): Resource\StorageRepository
260
    {
261
        return self::new($container, Resource\StorageRepository::class);
262
    }
263
264
    public static function getDependencyOrderingService(ContainerInterface $container): Service\DependencyOrderingService
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

264
    public static function getDependencyOrderingService(/** @scrutinizer ignore-unused */ ContainerInterface $container): Service\DependencyOrderingService

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
265
    {
266
        return new Service\DependencyOrderingService();
267
    }
268
269
    public static function getFlexFormService(ContainerInterface $container): Service\FlexFormService
270
    {
271
        return self::new($container, Service\FlexFormService::class);
272
    }
273
274
    public static function getOpcodeCacheService(ContainerInterface $container): Service\OpcodeCacheService
275
    {
276
        return self::new($container, Service\OpcodeCacheService::class);
277
    }
278
279
    public static function getTimeTracker(ContainerInterface $container): TimeTracker\TimeTracker
280
    {
281
        return self::new($container, TimeTracker\TimeTracker::class);
282
    }
283
284
    public static function getTypoScriptConstantConfigurationParser(ContainerInterface $container): TypoScript\Parser\ConstantConfigurationParser
285
    {
286
        return self::new($container, TypoScript\Parser\ConstantConfigurationParser::class);
287
    }
288
289
    public static function getTypoScriptService(ContainerInterface $container): TypoScript\TypoScriptService
290
    {
291
        return self::new($container, TypoScript\TypoScriptService::class);
292
    }
293
294
    public static function getRequestFactory(ContainerInterface $container): Http\RequestFactory
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

294
    public static function getRequestFactory(/** @scrutinizer ignore-unused */ ContainerInterface $container): Http\RequestFactory

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
295
    {
296
        return new Http\RequestFactory();
297
    }
298
299
    public static function getMiddlewareStackResolver(ContainerInterface $container): Http\MiddlewareStackResolver
300
    {
301
        return new Http\MiddlewareStackResolver(
302
            $container,
303
            $container->get(Service\DependencyOrderingService::class),
304
            $container->get('cache.core')
305
        );
306
    }
307
308
    public static function getMiddlewares(ContainerInterface $container): ArrayObject
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

308
    public static function getMiddlewares(/** @scrutinizer ignore-unused */ ContainerInterface $container): ArrayObject

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
309
    {
310
        return new ArrayObject();
311
    }
312
313
    public static function provideFallbackEventDispatcher(
314
        ContainerInterface $container,
315
        EventDispatcherInterface $eventDispatcher = null
316
    ): EventDispatcherInterface {
317
        // Provide a dummy / empty event dispatcher for the install tool when $eventDispatcher is null (that means when we run without symfony DI)
318
        return $eventDispatcher ?? new EventDispatcher\EventDispatcher(
319
            new EventDispatcher\ListenerProvider($container)
320
        );
321
    }
322
}
323