‪TYPO3CMS  10.4
ServiceProvider.php
Go to the documentation of this file.
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\Backend;
19 
20 use ArrayObject;
21 use Psr\Container\ContainerInterface;
28 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
36 
41 {
42  protected static function ‪getPackagePath(): string
43  {
44  return __DIR__ . '/../';
45  }
46 
47  public function ‪getFactories(): array
48  {
49  return [
50  Application::class => [ static::class, 'getApplication' ],
51  RequestHandler::class => [ static::class, 'getRequestHandler' ],
52  RouteDispatcher::class => [ static::class, 'getRouteDispatcher' ],
53  'backend.middlewares' => [ static::class, 'getBackendMiddlewares' ],
54  'backend.routes' => [ static::class, 'getBackendRoutes' ],
55  ];
56  }
57 
58  public function ‪getExtensions(): array
59  {
60  return [
61  Router::class => [ static::class, 'configureBackendRouter' ],
62  ] + parent::getExtensions();
63  }
64 
65  public static function ‪getApplication(ContainerInterface $container): ‪Application
66  {
67  $requestHandler = new ‪MiddlewareDispatcher(
68  $container->get(RequestHandler::class),
69  $container->get('backend.middlewares'),
70  $container
71  );
72  return new ‪Application(
73  $requestHandler,
74  $container->get(ConfigurationManager::class),
75  $container->get(Context::class)
76  );
77  }
78 
79  public static function ‪getRequestHandler(ContainerInterface $container): ‪RequestHandler
80  {
81  return new ‪RequestHandler($container->get(RouteDispatcher::class));
82  }
83 
84  public static function ‪getRouteDispatcher(ContainerInterface $container): ‪RouteDispatcher
85  {
86  return ‪self::new($container, RouteDispatcher::class, [$container]);
87  }
88 
95  public static function ‪getBackendMiddlewares(ContainerInterface $container): ArrayObject
96  {
97  return new ArrayObject($container->get(MiddlewareStackResolver::class)->resolve('backend'));
98  }
99 
100  public static function ‪configureBackendRouter(ContainerInterface $container, ‪Router $router = null): ‪Router
101  {
102  $router = $router ?? ‪self::new($container, Router::class);
103  $cache = $container->get('cache.core');
104 
105  $cacheIdentifier = 'BackendRoutes_' . sha1((string)(new ‪Typo3Version()) . ‪Environment::getProjectPath() . 'BackendRoutes');
106  $routesFromPackages = $cache->require($cacheIdentifier);
107  if ($routesFromPackages === false) {
108  $routesFromPackages = $container->get('backend.routes')->getArrayCopy();
109  $cache->set($cacheIdentifier, 'return ' . var_export($routesFromPackages, true) . ';');
110  }
111 
112  foreach ($routesFromPackages as $name => $options) {
113  $path = $options['path'];
114  unset($options['path']);
115  $route = new ‪Route($path, $options);
116  $router->addRoute($name, $route);
117  }
118 
119  return $router;
120  }
121 
122  public static function ‪getBackendRoutes(ContainerInterface $container): ArrayObject
123  {
124  return new ArrayObject();
125  }
126 }
‪TYPO3\CMS\Backend\Http\RouteDispatcher
Definition: RouteDispatcher.php:36
‪TYPO3\CMS\Backend\ServiceProvider\getRouteDispatcher
‪static getRouteDispatcher(ContainerInterface $container)
Definition: ServiceProvider.php:84
‪TYPO3\CMS\Core\Package\AbstractServiceProvider
Definition: AbstractServiceProvider.php:31
‪TYPO3\CMS\Backend\Http\Application
Definition: Application.php:36
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Backend
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Backend\ServiceProvider\getApplication
‪static getApplication(ContainerInterface $container)
Definition: ServiceProvider.php:65
‪TYPO3\CMS\Core\Http\MiddlewareStackResolver
Definition: MiddlewareStackResolver.php:33
‪TYPO3\CMS\Backend\ServiceProvider
Definition: ServiceProvider.php:41
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\new
‪static mixed new(ContainerInterface $container, string $className, array $constructorArguments=[])
Definition: AbstractServiceProvider.php:116
‪TYPO3\CMS\Backend\ServiceProvider\getFactories
‪getFactories()
Definition: ServiceProvider.php:47
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Backend\ServiceProvider\getPackagePath
‪static getPackagePath()
Definition: ServiceProvider.php:42
‪TYPO3\CMS\Backend\ServiceProvider\getBackendMiddlewares
‪static ArrayObject getBackendMiddlewares(ContainerInterface $container)
Definition: ServiceProvider.php:95
‪TYPO3\CMS\Core\Http\MiddlewareDispatcher
Definition: MiddlewareDispatcher.php:35
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:169
‪TYPO3\CMS\Backend\ServiceProvider\configureBackendRouter
‪static configureBackendRouter(ContainerInterface $container, Router $router=null)
Definition: ServiceProvider.php:100
‪TYPO3\CMS\Backend\ServiceProvider\getRequestHandler
‪static getRequestHandler(ContainerInterface $container)
Definition: ServiceProvider.php:79
‪TYPO3\CMS\Backend\Http\RequestHandler
Definition: RequestHandler.php:39
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:24
‪TYPO3\CMS\Backend\ServiceProvider\getBackendRoutes
‪static getBackendRoutes(ContainerInterface $container)
Definition: ServiceProvider.php:122
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:34
‪TYPO3\CMS\Backend\ServiceProvider\getExtensions
‪getExtensions()
Definition: ServiceProvider.php:58