[FEATURE] Add symfony dependency injection for core and extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / ServiceProvider.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Extbase;
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 use Psr\Container\ContainerInterface;
19 use TYPO3\CMS\Core\Cache\CacheManager;
20 use TYPO3\CMS\Core\Log\LogManager;
21 use TYPO3\CMS\Core\Package\AbstractServiceProvider;
22
23 /**
24 * @internal
25 */
26 class ServiceProvider extends AbstractServiceProvider
27 {
28 protected static function getPackagePath(): string
29 {
30 return __DIR__ . '/../';
31 }
32
33 public function getFactories(): array
34 {
35 return [
36 Object\Container\Container::class => [ static::class, 'getObjectContainer' ],
37 Object\ObjectManager::class => [ static::class, 'getObjectManager' ],
38 SignalSlot\Dispatcher::class => [ static::class, 'getSignalSlotDispatcher' ],
39 Configuration\ConfigurationManager::class => [ static::class, 'getConfigurationManager' ],
40 Reflection\ReflectionService::class => [ static::class, 'getReflectionService' ],
41 Service\EnvironmentService::class => [ static::class, 'getEnvironmentService' ],
42 Service\ExtensionService::class => [ static::class, 'getExtensionService' ],
43 Security\Cryptography\HashService::class => [ static::class, 'getHashService' ],
44 ];
45 }
46
47 public static function getObjectContainer(ContainerInterface $container): Object\Container\Container
48 {
49 return self::new($container, Object\Container\Container::class, [$container]);
50 }
51
52 public static function getObjectManager(ContainerInterface $container): Object\ObjectManager
53 {
54 return self::new($container, Object\ObjectManager::class, [$container, $container->get(Object\Container\Container::class)]);
55 }
56
57 public static function getSignalSlotDispatcher(ContainerInterface $container): SignalSlot\Dispatcher
58 {
59 $logger = $container->get(LogManager::class)->getLogger(SignalSlot\Dispatcher::class);
60 return self::new($container, SignalSlot\Dispatcher::class, [$container->get(Object\ObjectManager::class), $logger]);
61 }
62
63 public static function getConfigurationManager(ContainerInterface $container): Configuration\ConfigurationManager
64 {
65 return self::new($container, Configuration\ConfigurationManager::class, [
66 $container->get(Object\ObjectManager::class),
67 $container->get(Service\EnvironmentService::class),
68 ]);
69 }
70
71 public static function getReflectionService(ContainerInterface $container): Reflection\ReflectionService
72 {
73 return self::new($container, Reflection\ReflectionService::class, [$container->get(CacheManager::class)]);
74 }
75
76 public static function getEnvironmentService(ContainerInterface $container): Service\EnvironmentService
77 {
78 return self::new($container, Service\EnvironmentService::class);
79 }
80
81 public static function getExtensionService(ContainerInterface $container): Service\ExtensionService
82 {
83 $extensionService = self::new($container, Service\ExtensionService::class);
84 $extensionService->injectObjectManager($container->get(Object\ObjectManager::class));
85 $extensionService->injectConfigurationManager($container->get(Configuration\ConfigurationManager::class));
86 return $extensionService;
87 }
88
89 public static function getHashService(ContainerInterface $container): Security\Cryptography\HashService
90 {
91 return self::new($container, Security\Cryptography\HashService::class);
92 }
93 }