comparison vendor/symfony/validator/DependencyInjection/AddConstraintValidatorsPass.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
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\DependencyInjection;
13
14 use Symfony\Component\DependencyInjection\ContainerBuilder;
15 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16 use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
17 use Symfony\Component\DependencyInjection\Reference;
18
19 /**
20 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
21 * @author Robin Chalas <robin.chalas@gmail.com>
22 */
23 class AddConstraintValidatorsPass implements CompilerPassInterface
24 {
25 private $validatorFactoryServiceId;
26 private $constraintValidatorTag;
27
28 public function __construct($validatorFactoryServiceId = 'validator.validator_factory', $constraintValidatorTag = 'validator.constraint_validator')
29 {
30 $this->validatorFactoryServiceId = $validatorFactoryServiceId;
31 $this->constraintValidatorTag = $constraintValidatorTag;
32 }
33
34 public function process(ContainerBuilder $container)
35 {
36 if (!$container->hasDefinition($this->validatorFactoryServiceId)) {
37 return;
38 }
39
40 $validators = array();
41 foreach ($container->findTaggedServiceIds($this->constraintValidatorTag, true) as $id => $attributes) {
42 $definition = $container->getDefinition($id);
43
44 if (isset($attributes[0]['alias'])) {
45 $validators[$attributes[0]['alias']] = new Reference($id);
46 }
47
48 $validators[$definition->getClass()] = new Reference($id);
49 }
50
51 $container
52 ->getDefinition($this->validatorFactoryServiceId)
53 ->replaceArgument(0, ServiceLocatorTagPass::register($container, $validators))
54 ;
55 }
56 }