‪TYPO3CMS  ‪main
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\Frontend;
19 
20 use Psr\Container\ContainerInterface;
21 use Psr\Http\Message\ResponseInterface;
22 use Psr\Http\Message\ServerRequestInterface;
23 use Psr\Http\Server\RequestHandlerInterface;
30 
35 {
36  protected static function ‪getPackagePath(): string
37  {
38  return __DIR__ . '/../';
39  }
40 
41  protected static function ‪getPackageName(): string
42  {
43  return 'typo3/cms-frontend';
44  }
45 
46  public function ‪getFactories(): array
47  {
48  return [
49  Http\Application::class => ‪self::getApplication(...),
50  'frontend.middlewares' => ‪self::getFrontendMiddlewares(...),
51  ];
52  }
53 
54  public function ‪getExtensions(): array
55  {
56  return [
57  Http\RequestHandler::class => ‪self::provideFallbackRequestHandler(...),
58  ] + parent::getExtensions();
59  }
60 
61  public static function ‪getApplication(ContainerInterface $container): Http\Application
62  {
63  $requestHandler = new ‪MiddlewareDispatcher(
64  $container->get(Http\RequestHandler::class),
65  $container->get('frontend.middlewares'),
66  $container
67  );
68  return new ‪Http\Application(
69  $requestHandler,
70  $container->get(Context::class),
71  );
72  }
73 
74  public static function ‪provideFallbackRequestHandler(
75  ContainerInterface $container,
76  RequestHandlerInterface $requestHandler = null
77  ): RequestHandlerInterface {
78  // Provide fallback request handler instace for the case where the system is not installed yet (that means when we run without symfony DI).
79  // This request handler is intended to be never executed, as the frontend application will perform an early redirect to the install tool.
80  return $requestHandler ?? new class () implements RequestHandlerInterface {
81  public function handle(ServerRequestInterface $request): ResponseInterface
82  {
83  throw new \RuntimeException('not implemented', 1689684150);
84  }
85  };
86  }
87 
92  public static function ‪getFrontendMiddlewares(ContainerInterface $container): \ArrayObject
93  {
94  return new \ArrayObject($container->get(MiddlewareStackResolver::class)->resolve('frontend'));
95  }
96 }
‪TYPO3\CMS\Core\Package\AbstractServiceProvider
Definition: AbstractServiceProvider.php:38
‪TYPO3\CMS\Frontend\ServiceProvider\getFactories
‪getFactories()
Definition: ServiceProvider.php:46
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Http\MiddlewareStackResolver
Definition: MiddlewareStackResolver.php:31
‪TYPO3\CMS\Frontend\ServiceProvider\getExtensions
‪getExtensions()
Definition: ServiceProvider.php:54
‪TYPO3\CMS\Frontend\ServiceProvider\getPackagePath
‪static getPackagePath()
Definition: ServiceProvider.php:36
‪TYPO3\CMS\Frontend
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Frontend\ServiceProvider\getPackageName
‪static getPackageName()
Definition: ServiceProvider.php:41
‪TYPO3\CMS\Core\Http\MiddlewareDispatcher
Definition: MiddlewareDispatcher.php:35
‪TYPO3\CMS\Frontend\ServiceProvider\provideFallbackRequestHandler
‪static provideFallbackRequestHandler(ContainerInterface $container, RequestHandlerInterface $requestHandler=null)
Definition: ServiceProvider.php:74
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:23
‪TYPO3\CMS\Frontend\ServiceProvider\getApplication
‪static getApplication(ContainerInterface $container)
Definition: ServiceProvider.php:61
‪TYPO3\CMS\Frontend\ServiceProvider\getFrontendMiddlewares
‪static getFrontendMiddlewares(ContainerInterface $container)
Definition: ServiceProvider.php:92
‪TYPO3\CMS\Frontend\Http\Application
Definition: Application.php:35
‪TYPO3\CMS\Frontend\ServiceProvider
Definition: ServiceProvider.php:35