TYPO3 CMS  TYPO3_7-6
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  try {
95  return $this->dispatch($request);
96 
97  // When token was invalid redirect to login
98  } catch (InvalidRequestTokenException $e) {
99  $url = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
101  }
102  }
103 
104  // No route found, so the system proceeds in called entrypoint as fallback.
105  return null;
106  }
107 
114  protected function boot($proceedIfNoUserIsLoggedIn)
115  {
116  $this->bootstrap
117  ->checkLockedBackendAndRedirectOrDie()
118  ->checkBackendIpOrDie()
119  ->checkSslBackendAndRedirectIfNeeded()
120  ->initializeBackendRouter()
121  ->loadExtensionTables(true)
122  ->initializeSpriteManager()
123  ->initializeBackendUser()
124  ->initializeBackendAuthentication($proceedIfNoUserIsLoggedIn)
125  ->initializeLanguageObject()
126  ->initializeBackendTemplate()
127  ->endOutputBufferingAndCleanPreviousOutput()
128  ->initializeOutputCompression()
129  ->sendHttpHeaders();
130  }
131 
138  public function canHandleRequest(ServerRequestInterface $request)
139  {
140  return TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI);
141  }
142 
149  public function getPriority()
150  {
151  return 50;
152  }
153 
162  protected function dispatch($request)
163  {
165  $response = GeneralUtility::makeInstance(Response::class);
167  $dispatcher = GeneralUtility::makeInstance(RouteDispatcher::class);
168  return $dispatcher->dispatch($request, $response);
169  }
170 }
canHandleRequest(ServerRequestInterface $request)
handleRequest(ServerRequestInterface $request)
boot($proceedIfNoUserIsLoggedIn)
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:76