TYPO3  7.6
backend/Classes/Http/RequestHandler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\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 
24 
44 {
49  protected $bootstrap;
50 
56  public function __construct(Bootstrap $bootstrap)
57  {
58  $this->bootstrap = $bootstrap;
59  }
60 
67  public function handleRequest(ServerRequestInterface $request)
68  {
69  // enable dispatching via Request/Response logic only for typo3/index.php
70  // This fallback will be removed in TYPO3 CMS 8, as only index.php will be allowed
71  $path = substr($request->getUri()->getPath(), strlen(GeneralUtility::getIndpEnv('TYPO3_SITE_PATH')));
72  $routingEnabled = ($path === TYPO3_mainDir . 'index.php' || $path === TYPO3_mainDir);
73  $proceedIfNoUserIsLoggedIn = false;
74 
75  if ($routingEnabled) {
76  $pathToRoute = (string)$request->getQueryParams()['route'];
77  // Allow the login page to be displayed if routing is not used and on index.php
78  if (empty($pathToRoute)) {
79  $pathToRoute = '/login';
80  }
81  $request = $request->withAttribute('routePath', $pathToRoute);
82 
83  // Evaluate the constant for skipping the BE user check for the bootstrap
84  // should be handled differently in the future by checking the Bootstrap directly
85  if ($pathToRoute === '/login') {
86  $proceedIfNoUserIsLoggedIn = true;
87  }
88  }
89 
90  $this->boot($proceedIfNoUserIsLoggedIn);
91 
92  // Check if the router has the available route and dispatch.
93  if ($routingEnabled) {
94  return $this->dispatch($request);
95  }
96 
97  // No route found, so the system proceeds in called entrypoint as fallback.
98  return null;
99  }
100 
107  protected function boot($proceedIfNoUserIsLoggedIn)
108  {
109  $this->bootstrap
110  ->checkLockedBackendAndRedirectOrDie()
111  ->checkBackendIpOrDie()
112  ->checkSslBackendAndRedirectIfNeeded()
113  ->initializeBackendRouter()
114  ->loadExtensionTables(true)
115  ->initializeSpriteManager()
116  ->initializeBackendUser()
117  ->initializeBackendAuthentication($proceedIfNoUserIsLoggedIn)
118  ->initializeLanguageObject()
119  ->initializeBackendTemplate()
120  ->endOutputBufferingAndCleanPreviousOutput()
121  ->initializeOutputCompression()
122  ->sendHttpHeaders();
123  }
124 
131  public function canHandleRequest(ServerRequestInterface $request)
132  {
133  return (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI));
134  }
135 
142  public function getPriority()
143  {
144  return 50;
145  }
146 
155  protected function dispatch($request)
156  {
158  $response = GeneralUtility::makeInstance(Response::class);
160  $dispatcher = GeneralUtility::makeInstance(RouteDispatcher::class);
161  return $dispatcher->dispatch($request, $response);
162  }
163 }