‪TYPO3CMS  9.5
TypoScriptFrontendInitialization.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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 Doctrine\DBAL\Exception\ConnectionException;
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Server\MiddlewareInterface;
22 use Psr\Http\Server\RequestHandlerInterface;
23 use Psr\Log\LoggerAwareInterface;
24 use Psr\Log\LoggerAwareTrait;
30 
40 class ‪TypoScriptFrontendInitialization implements MiddlewareInterface, LoggerAwareInterface
41 {
42  use LoggerAwareTrait;
43 
52  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
53  {
54  ‪$GLOBALS['TSFE'] = GeneralUtility::makeInstance(
55  TypoScriptFrontendController::class,
56  null,
57  GeneralUtility::_GP('id'),
58  GeneralUtility::_GP('type'),
59  null,
60  GeneralUtility::_GP('cHash'),
61  null,
62  GeneralUtility::_GP('MP')
63  );
64  if (GeneralUtility::_GP('no_cache')) {
65  ‪$GLOBALS['TSFE']->set_no_cache('&no_cache=1 has been supplied, so caching is disabled! URL: "' . (string)$request->getUri() . '"');
66  }
67 
68  // Set up the database connection and see if the connection can be established
69  try {
70  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
71  $connection->connect();
72  } catch (ConnectionException | \RuntimeException $exception) {
73  $message = 'Cannot connect to the configured database';
74  $this->logger->emergency($message, ['exception' => $exception]);
75  try {
76  return GeneralUtility::makeInstance(ErrorController::class)->unavailableAction($request, $message);
77  } catch (‪ServiceUnavailableException $e) {
78  throw new ‪ServiceUnavailableException($message, 1526013723);
79  }
80  }
81  // Call post processing function for DB connection:
82  if (!empty(‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'])) {
83  trigger_error('The "connectToDB" hook will be removed in TYPO3 v10.0 in favor of PSR-15. Use a middleware instead.', E_USER_DEPRECATED);
84  $_params = ['pObj' => &‪$GLOBALS['TSFE']];
85  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef) {
86  GeneralUtility::callUserFunction($_funcRef, $_params, ‪$GLOBALS['TSFE']);
87  }
88  }
89 
90  return $handler->handle($request);
91  }
92 }
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: TypoScriptFrontendInitialization.php:52
‪TYPO3\CMS\Frontend\Controller\ErrorController
Definition: ErrorController.php:35
‪TYPO3\CMS\Frontend\Middleware
Definition: BackendUserAuthenticator.php:4
‪TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
Definition: ServiceUnavailableException.php:21
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization
Definition: TypoScriptFrontendInitialization.php:41