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

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)
 

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

Parameters
array$defaultAspects

Definition at line 63 of file Context.php.

Member Function Documentation

◆ getAspect()

◆ 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.

Parameters
string$name
string$property
mixed$default
Returns
‪mixed|null
Exceptions
AspectNotFoundException

Definition at line 144 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

Parameters
string$name
Returns
‪bool

Definition at line 78 of file Context.php.

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

◆ setAspect()

Member Data Documentation

◆ $aspects

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

Definition at line 56 of file Context.php.