2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2010-10-02 11:42:31 +01:00
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-10-02 11:42:31 +01:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-10-02 11:42:31 +01:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Validator;
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
|
|
|
|
use Symfony\Component\Validator\Constraint;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2011-01-16 04:41:23 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-06-24 09:40:05 +01:00
|
|
|
class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
protected $validators = array();
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2011-01-16 04:41:23 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2010-06-24 10:24:08 +01:00
|
|
|
public function getInstance(Constraint $constraint)
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
$className = $constraint->validatedBy();
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
if (!isset($this->validators[$className])) {
|
|
|
|
$this->validators[$className] = new $className();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->validators[$className];
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|