comparison vendor/symfony/validator/ConstraintValidatorFactory.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 }