[FOLLOWUP][FEATURE] Introduce Request/Response based on PSR-7
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Http / RequestHandler.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\ServerRequestInterface;
18 use TYPO3\CMS\Core\Core\Bootstrap;
19 use TYPO3\CMS\Core\Core\RequestHandlerInterface;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Default request handler for all requests inside the TYPO3 Install Tool, which does a simple hardcoded
24 * dispatching to a controller based on the get/post variable.
25 */
26 class RequestHandler implements RequestHandlerInterface {
27
28 /**
29 * Instance of the current TYPO3 bootstrap
30 * @var Bootstrap
31 */
32 protected $bootstrap;
33
34 /**
35 * Constructor handing over the bootstrap
36 *
37 * @param Bootstrap $bootstrap
38 */
39 public function __construct(Bootstrap $bootstrap) {
40 $this->bootstrap = $bootstrap;
41 }
42
43 /**
44 * Handles an install tool request
45 * Execute 'tool' or 'step' controller depending on install[controller] GET/POST parameter
46 *
47 * @param ServerRequestInterface $request
48 * @return void
49 */
50 public function handleRequest(ServerRequestInterface $request) {
51 $getPost = !empty($request->getQueryParams()['install']) ? $request->getQueryParams()['install'] : $request->getParsedBody()['install'];
52 switch ($getPost['controller']) {
53 case 'tool':
54 $controllerClassName = \TYPO3\CMS\Install\Controller\ToolController::class;
55 break;
56 case 'ajax':
57 $controllerClassName = \TYPO3\CMS\Install\Controller\AjaxController::class;
58 break;
59 default:
60 $controllerClassName = \TYPO3\CMS\Install\Controller\StepController::class;
61 }
62 GeneralUtility::makeInstance($controllerClassName)->execute();
63 }
64
65 /**
66 * This request handler can handle any request when not in CLI mode and the install tool flag is set
67 * please note that both checks are needed, as when in "failsafe" mode, the TYPO3_REQUESTTYPE is not
68 * necessarily set at this point.
69 *
70 * @param ServerRequestInterface $request
71 * @return bool Returns always TRUE
72 */
73 public function canHandleRequest(ServerRequestInterface $request) {
74 return TRUE;
75 }
76
77 /**
78 * Returns the priority - how eager the handler is to actually handle the request.
79 *
80 * @return int The priority of the request handler.
81 */
82 public function getPriority() {
83 return 20;
84 }
85 }