• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/Classes/Utility/FrontendSimulationUtility.php
1
<?php
2
namespace FluidTYPO3\Vhs\Utility;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Proxy\SiteFinderProxy;
12
use Psr\Http\Message\ServerRequestInterface;
13
use TYPO3\CMS\Core\Context\Context;
14
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
15
use TYPO3\CMS\Core\Http\ServerRequest;
16
use TYPO3\CMS\Core\Routing\PageArguments;
17
use TYPO3\CMS\Core\Site\Entity\Site;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
20
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
21

22
/**
23
 * Frontend Simulation Utility
24
 *
25
 * Utility to simulate frontend enviroment in backend enviroment.
26
 */
27
class FrontendSimulationUtility
28
{
29
    /**
30
     * Sets the global variable $GLOBALS['TYPO3_REQUEST'] with frontend.controller attribute in Backend mode.
31
     */
32
    public static function simulateFrontendEnvironment(): ?ServerRequestInterface
33
    {
34
        if (!ContextUtility::isBackend() || VersionUtility::isCoreAtLeast14()) {
29✔
35
            return null;
27✔
36
        }
37
        $requestBackup = $GLOBALS['TYPO3_REQUEST'] ?? null;
2✔
38

39
        $GLOBALS['TYPO3_CONF_VARS']['FE']['cookieName'] = $GLOBALS['TYPO3_CONF_VARS']['FE']['cookieName'] ?? 'fe_user';
2✔
40

41
        /** @var SiteFinderProxy $siteFinder */
42
        $siteFinder = GeneralUtility::makeInstance(SiteFinderProxy::class);
2✔
43
        $sites = $siteFinder->getAllSites();
2✔
44
        /** @var Context $context */
45
        $context = GeneralUtility::makeInstance(Context::class);
2✔
46
        /** @var Site $site */
47
        $site = reset($sites);
2✔
48
        $siteLanguage = $site->getDefaultLanguage();
2✔
49
        /** @var PageArguments $pageArguments */
50
        $pageArguments = GeneralUtility::makeInstance(
2✔
51
            PageArguments::class,
2✔
52
            0,
2✔
53
            (string) PageRepository::DOKTYPE_DEFAULT,
2✔
54
            []
2✔
55
        );
2✔
56
        /** @var FrontendUserAuthentication $frontendUser */
57
        $frontendUser = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
2✔
58

59
        /** @var class-string $controllerClassName */
60
        $controllerClassName = TypoScriptFrontendController::class;
2✔
61
        if (!class_exists($controllerClassName)) {
2✔
62
            return null;
×
63
        }
64

65
        $controller = GeneralUtility::makeInstance(
2✔
66
            $controllerClassName, // @phpstan-ignore-line The legacy controller class does not exist on TYPO3 v14.
2✔
67
            $context,
2✔
68
            $site,
2✔
69
            $siteLanguage,
2✔
70
            $pageArguments,
2✔
71
            $frontendUser
2✔
72
        );
2✔
73

74
        $GLOBALS['TSFE'] = $controller;
2✔
75

76
        $GLOBALS['TYPO3_REQUEST'] = ($GLOBALS['TYPO3_REQUEST'] ?? new ServerRequest())->withAttribute(
2✔
77
            'frontend.controller',
2✔
78
            $controller
2✔
79
        );
2✔
80

81
        return $requestBackup;
2✔
82
    }
83

84
    /**
85
     * Resets the frontend request if it was previously changed by simulateFrontendEnvironment()
86
     *
87
     * @see simulateFrontendEnvironment()
88
     */
89
    public static function resetFrontendEnvironment(?ServerRequestInterface $request): void
90
    {
91
        if (!ContextUtility::isBackend() || VersionUtility::isCoreAtLeast14()) {
26✔
92
            return;
24✔
93
        }
94

95
        unset($GLOBALS['TSFE']);
2✔
96

97
        if (!$request) {
2✔
98
            unset($GLOBALS['TYPO3_REQUEST']);
2✔
99
            return;
2✔
100
        }
101

102
        $GLOBALS['TYPO3_REQUEST'] = $request;
×
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc