[FEATURE] Add symfony dependency injection for core and extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / ServiceProvider.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend;
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\Exception\InvalidDataException;
20 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
21 use TYPO3\CMS\Core\Exception as CoreException;
22 use TYPO3\CMS\Core\Http\MiddlewareDispatcher;
23 use TYPO3\CMS\Core\Http\MiddlewareStackResolver;
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 Http\Application::class => [ static::class, 'getApplication' ],
40 Http\RequestHandler::class => [ static::class, 'getRequestHandler' ],
41 Http\RouteDispatcher::class => [ static::class, 'getRouteDispatcher' ],
42 'backend.middlewares' => [ static::class, 'getBackendMiddlewares' ],
43 ];
44 }
45
46 public static function getApplication(ContainerInterface $container): Http\Application
47 {
48 $requestHandler = new MiddlewareDispatcher(
49 $container->get(Http\RequestHandler::class),
50 $container->get('backend.middlewares'),
51 $container
52 );
53 return new Http\Application($requestHandler, $container->get(ConfigurationManager::class));
54 }
55
56 public static function getRequestHandler(ContainerInterface $container): Http\RequestHandler
57 {
58 return new Http\RequestHandler($container->get(Http\RouteDispatcher::class));
59 }
60
61 public static function getRouteDispatcher(ContainerInterface $container): Http\RouteDispatcher
62 {
63 return self::new($container, Http\RouteDispatcher::class, [$container]);
64 }
65
66 /**
67 * @param ContainerInterface $container
68 * @return array
69 * @throws InvalidDataException
70 * @throws CoreException
71 */
72 public static function getBackendMiddlewares(ContainerInterface $container): array
73 {
74 return $container->get(MiddlewareStackResolver::class)->resolve('backend');
75 }
76 }