[TASK] Create own response instance in controller actions
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / BackendModuleController.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Install\Controller;
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\Http\Message\ResponseInterface;
19 use TYPO3\CMS\Core\Http\RedirectResponse;
20 use TYPO3\CMS\Install\Service\SessionService;
21
22 /**
23 * Backend module controller to the install tool. Sets an install tool session
24 * marked as "initialized by a valid system administrator backend user" and
25 * redirects to the install tool entry point.
26 *
27 * This is a classic backend module that does not interfere with other code
28 * within the install tool, it can be seen as a facade around install tool just
29 * to embed the install tool in backend.
30 */
31 class BackendModuleController
32 {
33 /**
34 * Initialize session and redirect to "maintenance"
35 *
36 * @return ResponseInterface
37 */
38 public function maintenanceAction(): ResponseInterface
39 {
40 return $this->setAuthorizedAndRedirect('maintenance');
41 }
42
43 /**
44 * Initialize session and redirect to "settings"
45 *
46 * @return ResponseInterface
47 */
48 public function settingsAction(): ResponseInterface
49 {
50 return $this->setAuthorizedAndRedirect('settings');
51 }
52
53 /**
54 * Initialize session and redirect to "upgrade"
55 *
56 * @return ResponseInterface
57 */
58 public function upgradeAction(): ResponseInterface
59 {
60 return $this->setAuthorizedAndRedirect('upgrade');
61 }
62
63 /**
64 * Initialize session and redirect to "environment"
65 *
66 * @return ResponseInterface
67 */
68 public function environmentAction(): ResponseInterface
69 {
70 return $this->setAuthorizedAndRedirect('environment');
71 }
72
73 /**
74 * Starts / updates the session and redirects to the install tool
75 * with given action.
76 *
77 * @param $controller
78 * @return ResponseInterface
79 */
80 protected function setAuthorizedAndRedirect(string $controller): ResponseInterface
81 {
82 $sessionService = new SessionService();
83 $sessionService->setAuthorizedBackendSession();
84 $redirectLocation = 'install.php?install[controller]=' . $controller . '&install[context]=backend';
85 return new RedirectResponse($redirectLocation, 303);
86 }
87 }