‪TYPO3CMS  10.4
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;
35 
45 class ‪TypoScriptFrontendInitialization implements MiddlewareInterface
46 {
50  protected ‪$context;
51 
52  public function ‪__construct(‪Context ‪$context)
53  {
54  $this->context = ‪$context;
55  }
56 
64  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
65  {
66  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
68  $site = $request->getAttribute('site', null);
69  $pageArguments = $request->getAttribute('routing', null);
70  if (!$pageArguments instanceof ‪PageArguments) {
71  // Page Arguments must be set in order to validate. This middleware only works if PageArguments
72  // is available, and is usually combined with the Page Resolver middleware
73  return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
74  $request,
75  'Page Arguments could not be resolved',
77  );
78  }
79 
80  $controller = GeneralUtility::makeInstance(
81  TypoScriptFrontendController::class,
82  $this->context,
83  $site,
84  $request->getAttribute('language', $site->getDefaultLanguage()),
85  $pageArguments,
86  $request->getAttribute('frontend.user', null)
87  );
88  if ($pageArguments->getArguments()['no_cache'] ?? $request->getParsedBody()['no_cache'] ?? false) {
89  $controller->set_no_cache('&no_cache=1 has been supplied, so caching is disabled! URL: "' . (string)$request->getUri() . '"');
90  }
91  // Usually only set by the PageArgumentValidator
92  if ($request->getAttribute('noCache', false)) {
93  $controller->no_cache = 1;
94  }
95 
96  $controller->determineId($request);
97 
98  // No access? Then remove user and re-evaluate the page id
99  if ($controller->isBackendUserLoggedIn() && !‪$GLOBALS['BE_USER']->doesUserHaveAccess($controller->page, ‪Permission::PAGE_SHOW)) {
100  unset(‪$GLOBALS['BE_USER']);
101  // Register an empty backend user as aspect
102  $this->‪setBackendUserAspect(null);
103  $controller->determineId($request);
104  }
105 
106  // Make TSFE globally available
107  ‪$GLOBALS['TSFE'] = $controller;
108  return $handler->handle($request);
109  }
110 
116  protected function ‪setBackendUserAspect(?BackendUserAuthentication $user): void
117  {
118  $this->context->setAspect('backend.user', GeneralUtility::makeInstance(UserAspect::class, $user));
119  $this->context->setAspect('workspace', GeneralUtility::makeInstance(WorkspaceAspect::class, $user ? $user->workspace : 0));
120  }
121 }
‪TYPO3\CMS\Core\Routing\PageArguments
Definition: PageArguments.php:26
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Frontend\Page\PageAccessFailureReasons\INVALID_PAGE_ARGUMENTS
‪const INVALID_PAGE_ARGUMENTS
Definition: PageAccessFailureReasons.php:36
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\setBackendUserAspect
‪setBackendUserAspect(?BackendUserAuthentication $user)
Definition: TypoScriptFrontendInitialization.php:115
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: TypoScriptFrontendInitialization.php:63
‪TYPO3\CMS\Frontend\Controller\ErrorController
Definition: ErrorController.php:38
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:40
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\$context
‪Context $context
Definition: TypoScriptFrontendInitialization.php:49
‪TYPO3\CMS\Frontend\Middleware
Definition: BackendUserAuthenticator.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization\__construct
‪__construct(Context $context)
Definition: TypoScriptFrontendInitialization.php:51
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\Middleware\TypoScriptFrontendInitialization
Definition: TypoScriptFrontendInitialization.php:46
‪TYPO3\CMS\Frontend\Page\PageAccessFailureReasons
Definition: PageAccessFailureReasons.php:25
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:38