ApplicationType

FinalYes

Helper class to answer "Is this a frontend or backend request?".

It requires a PSR-7 ServerRequestInterface request object. Typical usage:

ApplicationType::fromRequest($request)->isFrontend()

Note the final request object is given to your controller by the frontend and backend RequestHandler's. This request should be used in code calling this class. However, various library parts of the TYPO3 core do not receive the request object directly, so extensions may not receive it either. To work around this technical debt for now, the RequestHandler's set the final request object as $GLOBALS['TYPO3_REQUEST'], which can be used in those cases to feed this class. Also note that CLI calls often do NOT create a request object, depending on their task.

Classes that may be called from CLI without request object thus use this helper like:

// Do something special if this is a frontend request.
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
    && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
) {

Important: $GLOBALS['TYPO3_REQUEST'] is NOT available before the RequestHandler has been called. This especially means the question "Is this a frontend or backend request?" can NOT be answered in the TYPO3 bootstrap related extension files ext_localconf.php, ext_tables.php and Configuration/TCA/* files.

Table of Contents

Methods

fromRequest()  : static
Create an ApplicationType object from a given PSR-7 request.
isBackend()  : bool
isFrontend()  : bool

Methods

fromRequest()

Create an ApplicationType object from a given PSR-7 request.

public static fromRequest(ServerRequestInterface $request) : static
Parameters
$request : ServerRequestInterface
Tags
throws
RuntimeException
Return values
static

isBackend()

public isBackend() : bool
Return values
bool

isFrontend()

public isFrontend() : bool
Return values
bool

        
On this page

Search results