You are here

class ConstraintValidatorFactory in Plug 7

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

5 files declare their use of ConstraintValidatorFactory
LegacyExecutionContextTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/LegacyExecutionContextTest.php
LegacyValidator2Dot5ApiTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php
LegacyValidatorLegacyApiTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php
RecursiveValidator2Dot5ApiTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php
ValidatorTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/ValidatorTest.php

File

lib/Symfony/validator/Symfony/Component/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
ConstraintValidatorFactory::__construct public function