interface ContextInterface implements ContextInterface, CacheableDependencyInterface (View source)

Context data and definitions for plugins supporting caching and return docs.

Methods

mixed
getContextValue()

Gets the context value.

bool
hasContextValue()

Returns whether the context has a value.

getContextDefinition()

Gets the provided definition that the context must conform to.

array
getConstraints()

Gets a list of validation constraints.

ConstraintViolationListInterface
validate()

Validates the set context value.

string[]
getCacheContexts()

The cache contexts associated with this object.

string[]
getCacheTags()

The cache tags associated with this object.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

getContextData()

Gets the context value as typed data object.

$this
addCacheableDependency(CacheableDependencyInterface|mixed $dependency)

Adds a dependency on an object: merges its cacheability metadata.

createFromContext(ContextInterface $old_context, mixed $value)

Creates a new context with a different value.

Details

mixed getContextValue()

Gets the context value.

Return Value

mixed

The currently set context value, or NULL if it is not set.

bool hasContextValue()

Returns whether the context has a value.

Return Value

bool

TRUE if the context has a value, FALSE otherwise.

ContextDefinitionInterface getContextDefinition()

Gets the provided definition that the context must conform to.

Return Value

ContextDefinitionInterface

The defining characteristic representation of the context.

array getConstraints()

Gets a list of validation constraints.

Return Value

array

Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.

ConstraintViolationListInterface validate()

Validates the set context value.

Return Value

ConstraintViolationListInterface

A list of constraint violations. If the list is empty, validation succeeded.

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

See also

CacheContextsManager::convertTokensToKeys

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

TypedDataInterface getContextData()

Gets the context value as typed data object.

Return Value

TypedDataInterface

$this addCacheableDependency(CacheableDependencyInterface|mixed $dependency)

Adds a dependency on an object: merges its cacheability metadata.

For example, when a context depends on some configuration, an entity, or an access result, we must make sure their cacheability metadata is present on the response. This method makes doing that simple.

Parameters

CacheableDependencyInterface|mixed $dependency

The dependency. If the object implements CacheableDependencyInterface, then its cacheability metadata will be used. Otherwise, the passed in object must be assumed to be uncacheable, so max-age 0 is set.

Return Value

$this

See also

CacheableMetadata::createFromObject

static ContextInterface createFromContext(ContextInterface $old_context, mixed $value)

Creates a new context with a different value.

Parameters

ContextInterface $old_context

The context object used to create a new object. Cacheability metadata will be copied over.

mixed $value

The value of the new context object.

Return Value

ContextInterface