‪TYPO3CMS  ‪main
TYPO3\CMS\Core\FormProtection\FormProtectionFactory Class Reference

Public Member Functions

 __construct (protected readonly FlashMessageService $flashMessageService, protected readonly LanguageServiceFactory $languageServiceFactory, protected readonly Registry $registry, protected readonly FrontendInterface $runtimeCache)
 
 createForType (string $type)
 
 createFromRequest (ServerRequestInterface $request)
 

Protected Member Functions

 determineTypeFromRequest (ServerRequestInterface $request)
 
array getClassNameAndConstructorArguments (string $type, ?ServerRequestInterface $request)
 
 getIdentifierForType (string $type)
 
 isInstallToolSession (ServerRequestInterface $request)
 
 isBackendSession ()
 
 isFrontendSession (ServerRequestInterface $request)
 
 getMessageClosure (LanguageService $languageService, FlashMessageQueue $messageQueue, bool $isAjaxCall)
 
 createInstance (string $className,... $constructorArguments)
 

Detailed Description

This class creates and manages instances of the various form protection classes.

Previously this class provides only provided static methods and could not be instantiated.

Since TYPO3 v12, this class can and should be used as a factory to be injected into other controllers or middlewares, to handle FormProtections for HTTP Requests.

Definition at line 42 of file FormProtectionFactory.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::__construct ( protected readonly FlashMessageService  $flashMessageService,
protected readonly LanguageServiceFactory  $languageServiceFactory,
protected readonly Registry  $registry,
protected readonly FrontendInterface  $runtimeCache 
)

Definition at line 44 of file FormProtectionFactory.php.

Member Function Documentation

◆ createForType()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::createForType ( string  $type)

Method should be used whenever you do not have direct access to the request object. It is however recommended to use createFromRequest() whenever you have a PSR-7 request object available.

Definition at line 56 of file FormProtectionFactory.php.

References $GLOBALS, TYPO3\CMS\Webhooks\Message\$identifier, TYPO3\CMS\Core\FormProtection\FormProtectionFactory\createInstance(), TYPO3\CMS\Core\FormProtection\FormProtectionFactory\getClassNameAndConstructorArguments(), and TYPO3\CMS\Core\FormProtection\FormProtectionFactory\getIdentifierForType().

◆ createFromRequest()

◆ createInstance()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::createInstance ( string  $className,
  $constructorArguments 
)
protected

Creates an instance for the requested class $className and stores it internally.

Parameters
class-string$className
array<int,mixed>‪$constructorArguments
Exceptions

Definition at line 204 of file FormProtectionFactory.php.

Referenced by TYPO3\CMS\Core\FormProtection\FormProtectionFactory\createForType(), and TYPO3\CMS\Core\FormProtection\FormProtectionFactory\createFromRequest().

◆ determineTypeFromRequest()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::determineTypeFromRequest ( ServerRequestInterface  $request)
protected

◆ getClassNameAndConstructorArguments()

array TYPO3\CMS\Core\FormProtection\FormProtectionFactory::getClassNameAndConstructorArguments ( string  $type,
?ServerRequestInterface  $request 
)
protected

This is the equivalent to getClassNameAndConstructorArgumentsByType() but non-static. It also does not handle "default" or class names, but is based on types previously resolved by the request. See determineTypeFromRequest()

Parameters
string$type‪Valid types: installtool, frontend, backend.
Returns
‪array Array of arguments

Definition at line 110 of file FormProtectionFactory.php.

References $GLOBALS, and TYPO3\CMS\Core\FormProtection\FormProtectionFactory\getMessageClosure().

Referenced by TYPO3\CMS\Core\FormProtection\FormProtectionFactory\createForType(), and TYPO3\CMS\Core\FormProtection\FormProtectionFactory\createFromRequest().

◆ getIdentifierForType()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::getIdentifierForType ( string  $type)
protected

Conveniant method to create a deterministic cache identifier.

Definition at line 151 of file FormProtectionFactory.php.

Referenced by TYPO3\CMS\Core\FormProtection\FormProtectionFactory\createForType(), and TYPO3\CMS\Core\FormProtection\FormProtectionFactory\createFromRequest().

◆ getMessageClosure()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::getMessageClosure ( LanguageService  $languageService,
FlashMessageQueue  $messageQueue,
bool  $isAjaxCall 
)
protected

◆ isBackendSession()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::isBackendSession ( )
protected

Checks if a user is logged in and the session is active.

Definition at line 167 of file FormProtectionFactory.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\FormProtection\FormProtectionFactory\determineTypeFromRequest().

◆ isFrontendSession()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::isFrontendSession ( ServerRequestInterface  $request)
protected

Checks if a frontend user is logged in and the session is active.

Definition at line 176 of file FormProtectionFactory.php.

Referenced by TYPO3\CMS\Core\FormProtection\FormProtectionFactory\determineTypeFromRequest().

◆ isInstallToolSession()

TYPO3\CMS\Core\FormProtection\FormProtectionFactory::isInstallToolSession ( ServerRequestInterface  $request)
protected