handle($request); } /** * Handles a backend request, after finishing running middlewares * Dispatch the request to the appropriate controller through the * Backend Dispatcher which resolves the routing * * @param ServerRequestInterface $request * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { // Use a custom pre-created response for AJAX calls // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0: No prepared $response to RouteDispatcher any longer if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) { $response = new Response('php://temp', 200, [ 'Content-Type' => 'application/json; charset=utf-8', 'X-JSON' => 'true' ]); } else { $response = new Response(); } try { // Check if the router has the available route and dispatch. $dispatcher = GeneralUtility::makeInstance(RouteDispatcher::class); return $dispatcher->dispatch($request, $response); } catch (InvalidRequestTokenException $e) { // When token was invalid redirect to login $url = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir; return new RedirectResponse($url); } } /** * This request handler can handle any backend request. * * @param ServerRequestInterface $request * @return bool If the request is BE request TRUE otherwise FALSE */ public function canHandleRequest(ServerRequestInterface $request): bool { return (bool)(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE); } /** * Returns the priority - how eager the handler is to actually handle the * request. * * @return int The priority of the request handler. */ public function getPriority(): int { return 50; } }