getQueryParams() due to * hooks who could have $_GET/$_POST modified before. * * @internal this middleware might get removed in TYPO3 v10.0. */ class TypoScriptFrontendInitialization implements MiddlewareInterface, LoggerAwareInterface { use LoggerAwareTrait; /** * Creates an instance of TSFE and sets it as a global variable, * also pings the database in order ensure a valid database connection. * * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $GLOBALS['TSFE'] = GeneralUtility::makeInstance( TypoScriptFrontendController::class, null, GeneralUtility::_GP('id'), GeneralUtility::_GP('type'), null, GeneralUtility::_GP('cHash'), null, GeneralUtility::_GP('MP') ); if (GeneralUtility::_GP('no_cache')) { $GLOBALS['TSFE']->set_no_cache('&no_cache=1 has been supplied, so caching is disabled! URL: "' . (string)$request->getUri() . '"'); } // Set up the database connection and see if the connection can be established try { $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages'); $connection->connect(); } catch (ConnectionException | \RuntimeException $exception) { $message = 'Cannot connect to the configured database'; $this->logger->emergency($message, ['exception' => $exception]); try { return GeneralUtility::makeInstance(ErrorController::class)->unavailableAction($request, $message); } catch (ServiceUnavailableException $e) { throw new ServiceUnavailableException($message, 1526013723); } } // Call post processing function for DB connection: if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'])) { trigger_error('The "connectToDB" hook will be removed in TYPO3 v10.0 in favor of PSR-15. Use a middleware instead.', E_USER_DEPRECATED); $_params = ['pObj' => &$GLOBALS['TSFE']]; foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef) { GeneralUtility::callUserFunction($_funcRef, $_params, $GLOBALS['TSFE']); } } return $handler->handle($request); } }