<?php/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/namespaceSymfony\Component\Validator;
useSymfony\Component\Validator\ConstraintValidatorFactoryInterface;
useSymfony\Component\Validator\Constraint;
/**
* Default implementation of the ConstraintValidatorFactoryInterface.
*
* This enforces the convention that the validatedBy() method on any
* Constrain will return the class name of the ConstraintValidator that
* should validate the Constraint.
*/class ConstraintValidatorFactoryimplements ConstraintValidatorFactoryInterface {
protected $validators = array();
/**
* {@inheritDoc}
*/
public functiongetInstance(Constraint $constraint) {
$className = $constraint
->validatedBy();
if (!isset($this->validators[$className])) {
$this->validators[$className] = new$className();
}
return$this->validators[$className];
}
}