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

Public Member Functions

 hasAspect (string $name)
 
 getAspect (string $name)
 
 getPropertyFromAspect (string $name, string $property, mixed $default=null)
 
 setAspect (string $name, AspectInterface $aspect)
 
 unsetAspect (string $name)
 

Protected Attributes

array $aspects = []
 

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]

Definition at line 53 of file Context.php.

Member Function Documentation

◆ getAspect()

◆ getPropertyFromAspect()

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

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

Exceptions
AspectNotFoundException

Definition at line 116 of file Context.php.

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

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

◆ hasAspect()

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

◆ setAspect()

◆ 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 143 of file Context.php.

Member Data Documentation

◆ $aspects

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

Definition at line 58 of file Context.php.