‪TYPO3CMS  11.5
TypoScriptFrontendInitialization.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\MiddlewareInterface;
23 use Psr\Http\Server\RequestHandlerInterface;
32 
42 class ‪TypoScriptFrontendInitialization implements MiddlewareInterface
43 {
47  protected ‪$context;
48 
49  public function ‪__construct(‪Context ‪$context)
50  {
51  $this->context = ‪$context;
52  }
53 
61  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
62  {
63  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
65  $site = $request->getAttribute('site', null);
66  $pageArguments = $request->getAttribute('routing', null);
67  if (!$pageArguments instanceof ‪PageArguments) {
68  // Page Arguments must be set in order to validate. This middleware only works if PageArguments
69  // is available, and is usually combined with the Page Resolver middleware
70  return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
71  $request,
72  'Page Arguments could not be resolved',
74  );
75  }
76  $frontendUser = $request->getAttribute('frontend.user');
77  if (!$frontendUser instanceof FrontendUserAuthentication) {
78  throw new \RuntimeException('The PSR-7 Request attribute "frontend.user" needs to be available as FrontendUserAuthentication object (as created by the FrontendUserAuthenticator middleware).', 1590740612);
79  }
80 
81  $controller = GeneralUtility::makeInstance(
82  TypoScriptFrontendController::class,
83  $this->context,
84  $site,
85  $request->getAttribute('language', $site->getDefaultLanguage()),
86  $pageArguments,
87  $frontendUser
88  );
89  if ($pageArguments->getArguments()['no_cache'] ?? $request->getParsedBody()['no_cache'] ?? false) {
90  $controller->set_no_cache('&no_cache=1 has been supplied, so caching is disabled! URL: "' . (string)$request->getUri() . '"');
91  }
92  // Usually only set by the PageArgumentValidator
93  if ($request->getAttribute('noCache', false)) {
94  $controller->no_cache = true;
95  }
96 
97  $controller->determineId($request);
98 
99  $request = $request->withAttribute('frontend.controller', $controller);
100  // Make TSFE globally available
101  // @todo deprecate $GLOBALS['TSFE'] once TSFE is retrieved from the
102  // PSR-7 request attribute frontend.controller throughout TYPO3 core
103  ‪$GLOBALS['TSFE'] = $controller;
104  return $handler->handle($request);
105  }
106 }
‪TYPO3\CMS\Core\Routing\PageArguments
Definition: PageArguments.php:26
‪TYPO3\CMS\Frontend\Page\PageAccessFailureReasons\INVALID_PAGE_ARGUMENTS
‪const INVALID_PAGE_ARGUMENTS
Definition: PageAccessFailureReasons.php:36
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: TypoScriptFrontendInitialization.php:60
‪TYPO3\CMS\Frontend\Controller\ErrorController
Definition: ErrorController.php:39
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\$context
‪Context $context
Definition: TypoScriptFrontendInitialization.php:46
‪TYPO3\CMS\Frontend\Middleware
Definition: BackendUserAuthenticator.php:18
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\__construct
‪__construct(Context $context)
Definition: TypoScriptFrontendInitialization.php:48
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:104
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization
Definition: TypoScriptFrontendInitialization.php:43
‪TYPO3\CMS\Frontend\Page\PageAccessFailureReasons
Definition: PageAccessFailureReasons.php:25