[TASK] Directly wire Application and RequestHandler
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Http / Application.php
1 <?php
2 namespace TYPO3\CMS\Install\Http;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Core\Cache\Backend\NullBackend;
20 use TYPO3\CMS\Core\Core\Bootstrap;
21 use TYPO3\CMS\Core\Http\AbstractApplication;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Entry point for the TYPO3 Install Tool
26 */
27 class Application extends AbstractApplication
28 {
29 /**
30 * @var Bootstrap
31 */
32 protected $bootstrap;
33
34 /**
35 * Number of subdirectories where the entry script is located, relative to PATH_site
36 * @var int
37 */
38 protected $entryPointLevel = 1;
39
40 /**
41 * All available request handlers that can handle an install tool request
42 * @var array
43 */
44 protected $availableRequestHandlers = [
45 \TYPO3\CMS\Install\Http\RequestHandler::class,
46 \TYPO3\CMS\Install\Http\InstallerRequestHandler::class
47 ];
48
49 /**
50 * Constructor setting up legacy constant and register available Request Handlers
51 *
52 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
53 */
54 public function __construct($classLoader)
55 {
56 $this->defineLegacyConstants();
57
58 $this->bootstrap = Bootstrap::getInstance()
59 ->initializeClassLoader($classLoader)
60 ->setRequestType(TYPO3_REQUESTTYPE_INSTALL)
61 ->baseSetup($this->entryPointLevel);
62
63 $this->bootstrap
64 ->startOutputBuffering()
65 ->loadConfigurationAndInitialize(false, \TYPO3\CMS\Core\Package\FailsafePackageManager::class);
66
67 $this->disableCachingFramework();
68 }
69
70 /**
71 * @param ServerRequestInterface $request
72 * @return ResponseInterface
73 */
74 protected function handle(ServerRequestInterface $request): ResponseInterface
75 {
76 foreach ($this->availableRequestHandlers as $requestHandler) {
77 $handler = GeneralUtility::makeInstance($requestHandler, $this->bootstrap);
78 if ($handler->canHandleRequest($request)) {
79 return $handler->handleRequest($request);
80 }
81 }
82
83 throw new \TYPO3\CMS\Core\Exception('No suitable request handler found.', 1518448686);
84 }
85
86 /**
87 * Set caching to NullBackend, install tool must not cache anything
88 */
89 protected function disableCachingFramework()
90 {
91 $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'];
92
93 $cacheConfigurationsWithCachesSetToNullBackend = [];
94 foreach ($cacheConfigurations as $cacheName => $cacheConfiguration) {
95 // cache_core is handled in bootstrap already
96 if (is_array($cacheConfiguration) && $cacheName !== 'cache_core') {
97 $cacheConfiguration['backend'] = NullBackend::class;
98 $cacheConfiguration['options'] = [];
99 }
100 $cacheConfigurationsWithCachesSetToNullBackend[$cacheName] = $cacheConfiguration;
101 }
102 /** @var $cacheManager \TYPO3\CMS\Core\Cache\CacheManager */
103 $cacheManager = $this->bootstrap->getEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
104 $cacheManager->setCacheConfigurations($cacheConfigurationsWithCachesSetToNullBackend);
105 }
106
107 /**
108 * Define constants
109 */
110 protected function defineLegacyConstants()
111 {
112 define('TYPO3_MODE', 'BE');
113 }
114 }