* @package Vhs * @subpackage Utility */ class FrontendSimulationUtility { /** * Sets the global variables $GLOBALS['TSFE']->csConvObj and $GLOBALS['TSFE']->renderCharset in Backend mode * This somewhat hacky work around is currently needed because the conv_case() and convCaseFirst() functions of tslib_cObj rely on those variables to be set * * @return mixed */ public static function simulateFrontendEnvironment() { if ('BE' !== TYPO3_MODE) { return; } $tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL; $GLOBALS['TSFE'] = new \stdClass(); // preparing csConvObj if (FALSE === is_object($GLOBALS['TSFE']->csConvObj)) { if (TRUE === is_object($GLOBALS['LANG'])) { $GLOBALS['TSFE']->csConvObj = $GLOBALS['LANG']->csConvObj; } else { $GLOBALS['TSFE']->csConvObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter'); } } // preparing renderCharset if (FALSE === is_object($GLOBALS['TSFE']->renderCharset)) { if (TRUE === is_object($GLOBALS['LANG'])) { $GLOBALS['TSFE']->renderCharset = $GLOBALS['LANG']->charSet; } else { $GLOBALS['TSFE']->renderCharset = 'utf-8'; } } return $tsfeBackup; } /** * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment() * * @param mixed $tsfeBackup * @return void * @see simulateFrontendEnvironment() */ public static function resetFrontendEnvironment($tsfeBackup) { if ('BE' !== TYPO3_MODE) { return; } $GLOBALS['TSFE'] = $tsfeBackup; } }