FormProtectionFactory
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.
Table of Contents
Properties
- $flashMessageService : FlashMessageService
- $languageServiceFactory : LanguageServiceFactory
- $registry : Registry
- $runtimeCache : FrontendInterface
Methods
- __construct() : mixed
- createForType() : AbstractFormProtection
- Method should be used whenever you do not have direct access to the request object.
- createFromRequest() : AbstractFormProtection
- Detect the right FormProtection implementation based on the request. Should be used instead of FormProtectionFactory::get()
- get() : AbstractFormProtection
- Gets a form protection instance for the requested type or class.
- purgeInstances() : void
- Purges all existing instances.
- createForClass() : AbstractFormProtection
- Create a concrete FormProtection implementation, using the provided arguments as constructor arguments.
- createInstance() : AbstractFormProtection
- Creates an instance for the requested class $className and stores it internally.
- determineTypeFromRequest() : string
- Detects the type of FormProtection which should be instantiated, based on the request.
- getClassNameAndConstructorArguments() : array<string|int, mixed>
- This is the equivalent to getClassNameAndConstructorArgumentsByType() but non-static.
- getIdentifierForType() : string
- Conveniant method to create a deterministic cache identifier.
- getMessageClosure() : Closure
- isBackendSession() : bool
- Checks if a user is logged in and the session is active.
- isFrontendSession() : bool
- Checks if a frontend user is logged in and the session is active.
- isInstallToolSession() : bool
- Check if we are in the install tool
Properties
$flashMessageService read-only
protected
FlashMessageService
$flashMessageService
$languageServiceFactory read-only
protected
LanguageServiceFactory
$languageServiceFactory
$registry read-only
protected
Registry
$registry
$runtimeCache read-only
protected
FrontendInterface
$runtimeCache
Methods
__construct()
public
__construct(FlashMessageService $flashMessageService, LanguageServiceFactory $languageServiceFactory, Registry $registry, FrontendInterface $runtimeCache) : mixed
Parameters
- $flashMessageService : FlashMessageService
- $languageServiceFactory : LanguageServiceFactory
- $registry : Registry
- $runtimeCache : FrontendInterface
createForType()
Method should be used whenever you do not have direct access to the request object.
public
createForType(string $type) : AbstractFormProtection
It is however recommended to use createFromRequest() whenever you have a PSR-7 request object available.
Parameters
- $type : string
Return values
AbstractFormProtectioncreateFromRequest()
Detect the right FormProtection implementation based on the request. Should be used instead of FormProtectionFactory::get()
public
createFromRequest(ServerRequestInterface $request) : AbstractFormProtection
Parameters
- $request : ServerRequestInterface
Return values
AbstractFormProtectionget()
Gets a form protection instance for the requested type or class.
public
static get([string $classNameOrType = 'default' ], array<int, mixed> ...$constructorArguments) : AbstractFormProtection
since v12, will be removed in v13 together with createForTypeWithArguments. Use a instance of FormProtectionFactory directly.
If there already is an existing instance of the requested $classNameOrType, the existing instance will be returned. If no $classNameOrType is provided, the factory detects the scope and returns the appropriate form protection object.
Parameters
- $classNameOrType : string = 'default'
-
Name of a form protection class, or one of the pre-defined form protection types: frontend, backend, installtool
- $constructorArguments : array<int, mixed>
-
Arguments for the class-constructor
Tags
Return values
AbstractFormProtection —the requested instance
purgeInstances()
Purges all existing instances.
public
static purgeInstances() : void
since v12, will be removed in v13. Internal cache has been replaced by runtime cache.
This function is particularly useful when cleaning up in unit testing.
createForClass()
Create a concrete FormProtection implementation, using the provided arguments as constructor arguments.
protected
createForClass(string $className, array<int, mixed> ...$constructorArguments) : AbstractFormProtection
since v12, will be removed in v13 together with get().
Should be used instead of FormProtectionFactory::get() is a custom FormProtection implementation must be instantiated.
For provided core implementation use
// auto-detected based on request
GeneralUtility::makeInstance(FormProtectionFactory::class)
->createFromRequest($GLOBAL['TYPO3_REQUEST']);
or // concrete implementation GeneralUtility::makeInstance(FormProtectionFactory::class) ->createForType($type); // 'installtool', 'backend', 'frontend', 'disabled'
Parameters
- $className : string
-
Name of a form protection class
- $constructorArguments : array<int, mixed>
-
Arguments for the class-constructor
Return values
AbstractFormProtectioncreateInstance()
Creates an instance for the requested class $className and stores it internally.
protected
createInstance(class-string $className, array<int, mixed> ...$constructorArguments) : AbstractFormProtection
Parameters
- $className : class-string
- $constructorArguments : array<int, mixed>
Tags
Return values
AbstractFormProtectiondetermineTypeFromRequest()
Detects the type of FormProtection which should be instantiated, based on the request.
protected
determineTypeFromRequest(ServerRequestInterface $request) : string
Parameters
- $request : ServerRequestInterface
Return values
stringgetClassNameAndConstructorArguments()
This is the equivalent to getClassNameAndConstructorArgumentsByType() but non-static.
protected
getClassNameAndConstructorArguments(string $type, ServerRequestInterface|null $request) : array<string|int, mixed>
It also does not handle "default" or class names, but is based on types previously resolved by the request. See determineTypeFromRequest()
Parameters
- $type : string
-
Valid types: installtool, frontend, backend.
- $request : ServerRequestInterface|null
Return values
array<string|int, mixed> —Array of arguments
getIdentifierForType()
Conveniant method to create a deterministic cache identifier.
protected
getIdentifierForType(string $type) : string
Parameters
- $type : string
Return values
stringgetMessageClosure()
protected
getMessageClosure(LanguageService $languageService, FlashMessageQueue $messageQueue, bool $isAjaxCall) : Closure
Parameters
- $languageService : LanguageService
- $messageQueue : FlashMessageQueue
- $isAjaxCall : bool
Return values
ClosureisBackendSession()
Checks if a user is logged in and the session is active.
protected
isBackendSession() : bool
Return values
boolisFrontendSession()
Checks if a frontend user is logged in and the session is active.
protected
isFrontendSession(ServerRequestInterface $request) : bool
Parameters
- $request : ServerRequestInterface
Return values
boolisInstallToolSession()
Check if we are in the install tool
protected
isInstallToolSession(ServerRequestInterface $request) : bool
Parameters
- $request : ServerRequestInterface