‪TYPO3CMS  11.5
TYPO3\CMS\Core\Context\Context Class Reference
Inheritance diagram for TYPO3\CMS\Core\Context\Context:

Public Member Functions

 __construct (array $defaultAspects=[])
bool hasAspect (string $name)
AspectInterface getAspect (string $name)
mixed null getPropertyFromAspect (string $name, string $property, $default=null)
 setAspect (string $name, AspectInterface $aspect)
 unsetAspect (string $name)

Protected Attributes

AspectInterface[] $aspects = array( )

Detailed Description

Contains the state of a current page request, to be used when reading information of the current request in which configuration/context it is used.

Typically, the current main context is initialized very early within each entry-point application, and is then modified overridden in e.g. PSR-15 middlewares (e.g. authentication, preview settings etc).

For most use-cases, the current main context is fetched via GeneralUtility::makeInstance(Context::class), however, if custom settings for a single use-case is necessary, it is recommended to clone the base context:

$mainContext = GeneralUtility::makeInstance(Context::class); $customContext = clone $mainContext; $customContext->setAspect(GeneralUtility::makeInstance(VisibilityAspect::class, true, true, false))

... which in turn can be injected in the various places where TYPO3 uses contexts.

Classic aspect names to be used are:

  • ‪date (DateTimeAspect)
  • ‪workspace
  • ‪visibility
  • ‪frontend.user
  • ‪backend.user
  • ‪language
  • ‪frontend.preview [if EXT:frontend is loaded]
  • ‪typoscript

Definition at line 52 of file Context.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Context\Context::__construct ( array  $defaultAspects = [])

Sets up the context with pre-defined aspects


Definition at line 63 of file Context.php.

Member Function Documentation

◆ getAspect()

AspectInterface TYPO3\CMS\Core\Context\Context::getAspect ( string  $name)

◆ getPropertyFromAspect()

mixed null TYPO3\CMS\Core\Context\Context::getPropertyFromAspect ( string  $name,
string  $property,
  $default = null 

Returns a property from the aspect, but only if the property is found.


Definition at line 149 of file Context.php.

References TYPO3\CMS\Core\Context\AspectInterface\get(), TYPO3\CMS\Core\Context\Context\getAspect(), and TYPO3\CMS\Core\Context\Context\hasAspect().

Referenced by TYPO3\CMS\FrontendLogin\Redirect\RedirectHandler\__construct().

◆ hasAspect()

bool TYPO3\CMS\Core\Context\Context::hasAspect ( string  $name)

Checks if an aspect exists in the context


Definition at line 78 of file Context.php.

Referenced by TYPO3\CMS\Core\Context\Context\getPropertyFromAspect().

◆ setAspect()

TYPO3\CMS\Core\Context\Context::setAspect ( string  $name,
AspectInterface  $aspect 

◆ unsetAspect()

TYPO3\CMS\Core\Context\Context::unsetAspect ( string  $name)

Using this method is a sign of a technical debt. It is used by RedirectService, but may vanish any time when this is fixed, and thus internal. In general, Context aspects should never have to be unset. When a middleware has to use this method, it is either located at the wrong position in the chain, or has some other dependency issue.

Definition at line 179 of file Context.php.

Member Data Documentation

◆ $aspects

AspectInterface [] TYPO3\CMS\Core\Context\Context::$aspects = array( )

Definition at line 56 of file Context.php.