Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExecutionContext.php

class ExecutionContext

Same name in this branch
  1. 11.1.x vendor/symfony/validator/Context/ExecutionContext.php \Symfony\Component\Validator\Context\ExecutionContext

Defines an execution context class.

We do not use the context provided by Symfony as it is marked internal, so this class is pretty much the same, but has some code style changes as well as exceptions for methods we don't support.

Hierarchy

  • class \Drupal\Core\Validation\ExecutionContext implements \Symfony\Component\Validator\Context\ExecutionContextInterface

Expanded class hierarchy of ExecutionContext

1 file declares its use of ExecutionContext
PrecedingConstraintAwareValidatorTrait.php in core/modules/ckeditor5/src/Plugin/Validation/Constraint/PrecedingConstraintAwareValidatorTrait.php

File

core/lib/Drupal/Core/Validation/ExecutionContext.php, line 23

Namespace

Drupal\Core\Validation
View source
class ExecutionContext implements ExecutionContextInterface {
    
    /**
     * The violations generated in the current context.
     */
    protected ConstraintViolationList $violations;
    
    /**
     * The currently validated value.
     */
    protected mixed $value = NULL;
    
    /**
     * The currently validated object.
     */
    protected ?object $object = NULL;
    
    /**
     * The property path leading to the current value.
     */
    protected string $propertyPath = '';
    
    /**
     * The current validation metadata.
     */
    protected ?MetadataInterface $metadata = NULL;
    
    /**
     * The currently validated group.
     */
    protected ?string $group;
    
    /**
     * The currently validated constraint.
     */
    protected ?Constraint $constraint;
    
    /**
     * Stores which objects have been validated in which group.
     */
    protected array $validatedObjects = [];
    
    /**
     * Stores which class constraint has been validated for which object.
     */
    protected array $validatedConstraints = [];
    
    /**
     * Creates a new ExecutionContext.
     *
     * @param \Symfony\Component\Validator\Validator\ValidatorInterface $validator
     *   The validator.
     * @param mixed $root
     *   The root.
     * @param \Drupal\Core\Validation\TranslatorInterface $translator
     *   The translator.
     * @param string|null $translationDomain
     *   (optional) The translation domain.
     *
     * @internal Called by \Drupal\Core\Validation\ExecutionContextFactory.
     *    Should not be used in user code.
     */
    public function __construct(ValidatorInterface $validator, mixed $root, TranslatorInterface $translator, ?string $translationDomain = NULL) {
        $this->violations = new ConstraintViolationList();
    }
    
    /**
     * {@inheritdoc}
     */
    public function setNode(mixed $value, ?object $object, ?MetadataInterface $metadata, string $propertyPath) : void {
        $this->value = $value;
        $this->object = $object;
        $this->metadata = $metadata;
        $this->propertyPath = $propertyPath;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setConstraint(Constraint $constraint) : void {
        $this->constraint = $constraint;
    }
    
    /**
     * {@inheritdoc}
     */
    public function addViolation(string $message, array $params = []) : void {
        $this->violations
            ->add(new ConstraintViolation($this->translator
            ->trans($message, $params, $this->translationDomain), $message, $params, $this->root, $this->propertyPath, $this->value, NULL, NULL, $this->constraint));
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildViolation(string $message, array $parameters = []) : ConstraintViolationBuilderInterface {
        return new ConstraintViolationBuilder($this->violations, $this->constraint, $message, $parameters, $this->root, $this->propertyPath, $this->value, $this->translator, $this->translationDomain);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getViolations() : ConstraintViolationListInterface {
        return $this->violations;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getValidator() : ValidatorInterface {
        return $this->validator;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRoot() : mixed {
        return $this->root;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getValue() : mixed {
        return $this->value;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getObject() : ?object {
        return $this->object;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getMetadata() : ?MetadataInterface {
        return $this->metadata;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getGroup() : ?string {
        return Constraint::DEFAULT_GROUP;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setGroup(?string $group) : void {
        $this->group = $group;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getClassName() : ?string {
        return get_class($this->object);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPropertyName() : ?string {
        return $this->metadata instanceof PropertyMetadataInterface ? $this->metadata
            ->getPropertyName() : NULL;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPropertyPath(string $subPath = '') : string {
        return PropertyPath::append($this->propertyPath, $subPath);
    }
    
    /**
     * {@inheritdoc}
     */
    public function markConstraintAsValidated(string $cacheKey, string $constraintHash) : void {
        $this->validatedConstraints[$cacheKey . ':' . $constraintHash] = TRUE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isConstraintValidated(string $cacheKey, string $constraintHash) : bool {
        return isset($this->validatedConstraints[$cacheKey . ':' . $constraintHash]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function markGroupAsValidated(string $cacheKey, string $groupHash) : void {
        $this->validatedObjects[$cacheKey][$groupHash] = TRUE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function isGroupValidated(string $cacheKey, string $groupHash) : bool {
        return isset($this->validatedObjects[$cacheKey][$groupHash]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function markObjectAsInitialized(string $cacheKey) : void {
        throw new \LogicException(ExecutionContextInterface::class . '::markObjectAsInitialized is unsupported.');
    }
    
    /**
     * {@inheritdoc}
     */
    public function isObjectInitialized(string $cacheKey) : bool {
        throw new \LogicException(ExecutionContextInterface::class . '::isObjectInitialized is unsupported.');
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExecutionContext::$constraint protected property The currently validated constraint.
ExecutionContext::$group protected property The currently validated group.
ExecutionContext::$metadata protected property The current validation metadata.
ExecutionContext::$object protected property The currently validated object.
ExecutionContext::$propertyPath protected property The property path leading to the current value.
ExecutionContext::$validatedConstraints protected property Stores which class constraint has been validated for which object.
ExecutionContext::$validatedObjects protected property Stores which objects have been validated in which group.
ExecutionContext::$value protected property The currently validated value.
ExecutionContext::$violations protected property The violations generated in the current context.
ExecutionContext::addViolation public function Adds a violation at the current node of the validation graph. Overrides ExecutionContextInterface::addViolation
ExecutionContext::buildViolation public function Returns a builder for adding a violation with extended information. Overrides ExecutionContextInterface::buildViolation
ExecutionContext::getClassName public function Returns the class name of the current node. Overrides ExecutionContextInterface::getClassName
ExecutionContext::getGroup public function Returns the validation group that is currently being validated. Overrides ExecutionContextInterface::getGroup
ExecutionContext::getMetadata public function Returns the metadata for the currently validated value. Overrides ExecutionContextInterface::getMetadata
ExecutionContext::getObject public function Returns the currently validated object. Overrides ExecutionContextInterface::getObject
ExecutionContext::getPropertyName public function Returns the property name of the current node. Overrides ExecutionContextInterface::getPropertyName
ExecutionContext::getPropertyPath public function Returns the property path to the value that the validator is currently
validating.
Overrides ExecutionContextInterface::getPropertyPath
ExecutionContext::getRoot public function Returns the value at which validation was started in the object graph. Overrides ExecutionContextInterface::getRoot
ExecutionContext::getValidator public function Returns the validator. Overrides ExecutionContextInterface::getValidator
ExecutionContext::getValue public function Returns the value that the validator is currently validating. Overrides ExecutionContextInterface::getValue
ExecutionContext::getViolations public function Returns the violations generated by the validator so far. Overrides ExecutionContextInterface::getViolations
ExecutionContext::isConstraintValidated public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::isConstraintValidated
ExecutionContext::isGroupValidated public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::isGroupValidated
ExecutionContext::isObjectInitialized public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::isObjectInitialized
ExecutionContext::markConstraintAsValidated public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::markConstraintAsValidated
ExecutionContext::markGroupAsValidated public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::markGroupAsValidated
ExecutionContext::markObjectAsInitialized public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::markObjectAsInitialized
ExecutionContext::setConstraint public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::setConstraint
ExecutionContext::setGroup public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::setGroup
ExecutionContext::setNode public function Warning: Should not be called by user code, to be used by the validator engine only. Overrides ExecutionContextInterface::setNode
ExecutionContext::__construct public function Creates a new ExecutionContext.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal