4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator;
14 use Symfony\Component\Validator\Constraints\ExpressionValidator;
17 * Default implementation of the ConstraintValidatorFactoryInterface.
19 * This enforces the convention that the validatedBy() method on any
20 * Constraint will return the class name of the ConstraintValidator that
21 * should validate the Constraint.
23 * @author Bernhard Schussek <bschussek@gmail.com>
25 class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
27 protected $validators = array();
29 public function __construct()
36 public function getInstance(Constraint $constraint)
38 $className = $constraint->validatedBy();
40 if (!isset($this->validators[$className])) {
41 $this->validators[$className] = 'validator.expression' === $className
42 ? new ExpressionValidator()
46 return $this->validators[$className];