class Context implements ContextInterface (View source)

A generic context class for wrapping data a plugin needs to operate.

Properties

protected mixed $contextValue

The value of the context.

protected ContextDefinitionInterface $contextDefinition

The definition to which a context must conform.

Methods

__construct(ContextDefinitionInterface $context_definition, mixed|null $context_value = NULL)

Create a context object.

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.

Details

__construct(ContextDefinitionInterface $context_definition, mixed|null $context_value = NULL)

Create a context object.

Parameters

ContextDefinitionInterface $context_definition

The context definition.

mixed|null $context_value

The value of the context.

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.