Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / validator / ConstraintValidatorFactory.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator;
13
14 use Symfony\Component\Validator\Constraints\ExpressionValidator;
15
16 /**
17  * Default implementation of the ConstraintValidatorFactoryInterface.
18  *
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.
22  *
23  * @author Bernhard Schussek <bschussek@gmail.com>
24  */
25 class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
26 {
27     protected $validators = array();
28
29     private $propertyAccessor;
30
31     public function __construct($propertyAccessor = null)
32     {
33         $this->propertyAccessor = $propertyAccessor;
34     }
35
36     /**
37      * {@inheritdoc}
38      */
39     public function getInstance(Constraint $constraint)
40     {
41         $className = $constraint->validatedBy();
42
43         if (!isset($this->validators[$className])) {
44             $this->validators[$className] = 'validator.expression' === $className
45                 ? new ExpressionValidator($this->propertyAccessor)
46                 : new $className();
47         }
48
49         return $this->validators[$className];
50     }
51 }