Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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     public function __construct()
30     {
31     }
32
33     /**
34      * {@inheritdoc}
35      */
36     public function getInstance(Constraint $constraint)
37     {
38         $className = $constraint->validatedBy();
39
40         if (!isset($this->validators[$className])) {
41             $this->validators[$className] = 'validator.expression' === $className
42                 ? new ExpressionValidator()
43                 : new $className();
44         }
45
46         return $this->validators[$className];
47     }
48 }