73 public static function get($classNameOrType =
'default', ...$constructorArguments)
75 if (isset(self::$instances[$classNameOrType])) {
76 return self::$instances[$classNameOrType];
78 if ($classNameOrType ===
'default' || $classNameOrType ===
'installtool' || $classNameOrType ===
'frontend' || $classNameOrType ===
'backend') {
82 self::$instances[$classNameOrType] =
self::createInstance($classNameOrType, ...$constructorArguments);
84 return self::$instances[$classNameOrType];
96 if (self::isInstallToolSession() && ($type ===
'default' || $type ===
'installtool')) {
97 $classNameAndConstructorArguments = [
98 InstallToolFormProtection::class
100 } elseif (self::isFrontendSession() && ($type ===
'default' || $type ===
'frontend')) {
101 $classNameAndConstructorArguments = [
102 FrontendFormProtection::class,
105 } elseif (self::isBackendSession() && ($type ===
'default' || $type ===
'backend')) {
106 $classNameAndConstructorArguments = [
107 BackendFormProtection::class,
109 GeneralUtility::makeInstance(Registry::class),
112 GeneralUtility::makeInstance(FlashMessageService::class)->getMessageQueueByIdentifier(),
113 (
bool)(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)
118 $classNameAndConstructorArguments = [
119 DisabledFormProtection::class
122 return $classNameAndConstructorArguments;
132 return TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL;
164 return function () use ($languageService, $messageQueue, $isAjaxCall) {
166 $flashMessage = GeneralUtility::makeInstance(
168 $languageService->
sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:error.formProtection.tokenInvalid'),
173 $messageQueue->
enqueue($flashMessage);
186 protected static function createInstance($className, ...$constructorArguments)
188 if (!class_exists($className)) {
189 throw new \InvalidArgumentException(
'$className must be the name of an existing class, but ' .
'actually was "' . $className .
'".', 1285352962);
191 $instance = GeneralUtility::makeInstance($className, ...$constructorArguments);
193 throw new \InvalidArgumentException(
'$className must be a subclass of ' . AbstractFormProtection::class .
', but actually was "' . $className .
'".', 1285353026);
210 self::$instances[$classNameOrType] = $instance;
220 foreach (self::$instances as $key => $instance) {
221 unset(self::$instances[$key]);