‪TYPO3CMS  10.4
TYPO3\CMS\Core\Http\ApplicationType Class Reference

Public Member Functions

 isFrontend ()
 
 isBackend ()
 

Static Public Member Functions

static static fromRequest (ServerRequestInterface $request)
 

Private Member Functions

 __construct (int $type)
 

Private Attributes

int $type = 0
 

Detailed Description

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.

Definition at line 51 of file ApplicationType.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Http\ApplicationType::__construct ( int  $type)
private

Definition at line 76 of file ApplicationType.php.

References TYPO3\CMS\Core\Http\ApplicationType\$type.

Member Function Documentation

◆ fromRequest()

◆ isBackend()

TYPO3\CMS\Core\Http\ApplicationType::isBackend ( )

◆ isFrontend()

TYPO3\CMS\Core\Http\ApplicationType::isFrontend ( )

Member Data Documentation

◆ $type

int TYPO3\CMS\Core\Http\ApplicationType::$type = 0
private