You are here

class ConstraintValidatorFactory in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/validator/ConstraintValidatorFactory.php \Symfony\Component\Validator\ConstraintValidatorFactory
  2. 8 core/lib/Drupal/Core/Validation/ConstraintValidatorFactory.php \Drupal\Core\Validation\ConstraintValidatorFactory
Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/ConstraintValidatorFactory.php \Symfony\Component\Validator\ConstraintValidatorFactory

Default implementation of the ConstraintValidatorFactoryInterface.

This enforces the convention that the validatedBy() method on any Constraint will return the class name of the ConstraintValidator that should validate the Constraint.

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

Expanded class hierarchy of ConstraintValidatorFactory

7 files declare their use of ConstraintValidatorFactory
ConstraintValidatorFactory.php in core/lib/Drupal/Core/Validation/ConstraintValidatorFactory.php
Contains \Drupal\Core\Validation\ConstraintValidatorFactory.
LegacyExecutionContextTest.php in vendor/symfony/validator/Tests/LegacyExecutionContextTest.php
LegacyValidator2Dot5ApiTest.php in vendor/symfony/validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php
LegacyValidatorLegacyApiTest.php in vendor/symfony/validator/Tests/Validator/LegacyValidatorLegacyApiTest.php
LegacyValidatorTest.php in vendor/symfony/validator/Tests/LegacyValidatorTest.php

... See full list

File

vendor/symfony/validator/ConstraintValidatorFactory.php, line 25

Namespace

Symfony\Component\Validator
View source
class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface {
  protected $validators = array();
  private $propertyAccessor;
  public function __construct($propertyAccessor = null) {
    $this->propertyAccessor = $propertyAccessor;
  }

  /**
   * {@inheritdoc}
   */
  public function getInstance(Constraint $constraint) {
    $className = $constraint
      ->validatedBy();
    if (!isset($this->validators[$className])) {
      $this->validators[$className] = 'validator.expression' === $className ? new ExpressionValidator($this->propertyAccessor) : new $className();
    }
    return $this->validators[$className];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConstraintValidatorFactory::$propertyAccessor private property
ConstraintValidatorFactory::$validators protected property
ConstraintValidatorFactory::getInstance public function Given a Constraint, this returns the ConstraintValidatorInterface object that should be used to verify its validity. Overrides ConstraintValidatorFactoryInterface::getInstance 1
ConstraintValidatorFactory::__construct public function 1