Last active
January 20, 2023 07:31
-
-
Save neufeind/ff2b4db00fac4b3efab5c45f9b3a7784 to your computer and use it in GitHub Desktop.
TYPO3 v10: Init Frontend-environment for use in CLI- or BE-context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function initFrontend() { | |
$siteId = 1; | |
$pageId = 1219; | |
$typeNum = 0; | |
if (!is_object($GLOBALS['TT'])) { | |
$GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\TimeTracker; | |
$GLOBALS['TT']->start(); | |
} | |
$context = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class); | |
$siteFinder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Site\SiteFinder::class); | |
$site = $siteFinder->getSiteByRootPageId($siteId); | |
$siteLanguage = $site->getDefaultLanguage(); | |
$request = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\ServerRequest::class); | |
$GLOBALS['TYPO3_REQUEST'] = $request; | |
$pageArguments = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Routing\PageArguments::class, $pageId, $typeNum, []); | |
$frontendUserAuthentication = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::class); | |
$GLOBALS['TSFE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, $context, $site, $siteLanguage, $pageArguments, $frontendUserAuthentication); | |
$GLOBALS['TSFE']->determineId(); | |
// needed since otherwise overriding $_SERVER-variables will not work because of a cache in GeneralUtility | |
\TYPO3\CMS\Core\Utility\GeneralUtility::flushInternalRuntimeCaches(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment