2 namespace TYPO3\CMS\Core\FormProtection;
67 public static function get($className =
'default')
69 if (isset(self::$instances[$className])) {
70 return self::$instances[$className];
72 if ($className ===
'default') {
73 $classNameAndConstructorArguments = self::getClassNameAndConstructorArgumentsByState();
75 $classNameAndConstructorArguments = func_get_args();
77 self::$instances[$className] = self::createInstance($classNameAndConstructorArguments);
78 return self::$instances[$className];
90 case self::isInstallToolSession():
91 $classNameAndConstructorArguments = [
92 InstallToolFormProtection::class
95 case self::isFrontendSession():
96 $classNameAndConstructorArguments = [
97 FrontendFormProtection::class,
101 case self::isBackendSession():
102 $classNameAndConstructorArguments = [
103 BackendFormProtection::class,
106 self::getMessageClosure(
109 (
bool)(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)
114 $classNameAndConstructorArguments = [
115 DisabledFormProtection::class
118 return $classNameAndConstructorArguments;
128 return defined(
'TYPO3_enterInstallScript') && TYPO3_enterInstallScript;
138 return isset(
$GLOBALS[
'BE_USER']) &&
$GLOBALS[
'BE_USER'] instanceof \TYPO3\CMS\Core\Authentication\BackendUserAuthentication && isset(
$GLOBALS[
'BE_USER']->user[
'uid']);
148 return TYPO3_MODE ===
'FE' && is_object(
$GLOBALS[
'TSFE']) &&
$GLOBALS[
'TSFE']->fe_user instanceof \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication && isset(
$GLOBALS[
'TSFE']->fe_user->user[
'uid']);
160 return function () use ($languageService, $messageQueue, $isAjaxCall) {
163 \TYPO3\CMS\Core\Messaging\FlashMessage::class,
164 $languageService->
sL(
'LLL:EXT:lang/locallang_core.xlf:error.formProtection.tokenInvalid'),
166 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
169 $messageQueue->
enqueue($flashMessage);
181 protected static function createInstance(array $classNameAndConstructorArguments)
183 $className = $classNameAndConstructorArguments[0];
184 if (!class_exists($className)) {
185 throw new \InvalidArgumentException(
'$className must be the name of an existing class, but ' .
'actually was "' . $className .
'".', 1285352962);
187 $instance = call_user_func_array([\TYPO3\CMS\Core\Utility\GeneralUtility::class,
'makeInstance'], $classNameAndConstructorArguments);
189 throw new \InvalidArgumentException(
'$className must be a subclass of ' . AbstractFormProtection::class .
', but actually was "' . $className .
'".', 1285353026);
207 self::$instances[$className] = $instance;
219 foreach (self::$instances as $key => $instance) {
220 unset(self::$instances[$key]);