[FEATURE] Add symfony dependency injection for core and extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ServiceProvider.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Install;
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\Configuration\ConfigurationManager;
20 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
21 use TYPO3\CMS\Core\Http\MiddlewareDispatcher;
22 use TYPO3\CMS\Core\Package\AbstractServiceProvider;
23 use TYPO3\CMS\Core\Package\PackageManager;
24
25 /**
26 * @internal
27 */
28 class ServiceProvider extends AbstractServiceProvider
29 {
30 protected static function getPackagePath(): string
31 {
32 return __DIR__ . '/../';
33 }
34
35 public function getFactories(): array
36 {
37 return [
38 Http\Application::class => [ static::class, 'getApplication' ],
39 Http\NotFoundRequestHandler::class => [ static::class, 'getNotFoundRequestHandler' ],
40 Service\LateBootService::class => [ static::class, 'getLateBootService' ],
41 Service\ClearCacheService::class => [ static::class, 'getClearCacheService' ],
42 Service\LoadTcaService::class => [ static::class, 'getLoadTcaService' ],
43 Middleware\Maintenance::class => [ static::class, 'getMaintenanceMiddleware' ],
44 Controller\UpgradeController::class => [ static::class, 'getUpgradeController' ],
45 ];
46 }
47
48 public static function getApplication(ContainerInterface $container): Http\Application
49 {
50 $requestHandler = $container->get(Http\NotFoundRequestHandler::class);
51 $dispatcher = new MiddlewareDispatcher($requestHandler, [], $container);
52
53 // Stack of middlewares, executed LIFO
54 $dispatcher->lazy(Middleware\Installer::class);
55 $dispatcher->add($container->get(Middleware\Maintenance::class));
56
57 return new Http\Application($dispatcher);
58 }
59
60 public static function getNotFoundRequestHandler(ContainerInterface $container): Http\NotFoundRequestHandler
61 {
62 return new Http\NotFoundRequestHandler;
63 }
64
65 public static function getLateBootService(ContainerInterface $container): Service\LateBootService
66 {
67 return new Service\LateBootService(
68 $container->get(ContainerBuilder::class),
69 $container
70 );
71 }
72
73 public static function getClearCacheService(ContainerInterface $container): Service\ClearCacheService
74 {
75 return new Service\ClearCacheService($container->get(Service\LateBootService::class));
76 }
77
78 public static function getLoadTcaService(ContainerInterface $container): Service\LoadTcaService
79 {
80 return new Service\LoadTcaService($container->get(Service\LateBootService::class));
81 }
82
83 public static function getMaintenanceMiddleware(ContainerInterface $container): Middleware\Maintenance
84 {
85 return new Middleware\Maintenance(
86 $container->get(ConfigurationManager::class),
87 $container
88 );
89 }
90
91 public static function getUpgradeController(ContainerInterface $container): Controller\UpgradeController
92 {
93 return new Controller\UpgradeController(
94 $container->get(PackageManager::class),
95 $container->get(Service\LateBootService::class)
96 );
97 }
98 }