330f578f033f44728d6a6348c429d765a692559e
[yaffs-website] / vendor / symfony / validator / DependencyInjection / AddValidatorInitializersPass.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\DependencyInjection;
13
14 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Reference;
17
18 /**
19  * @author Fabien Potencier <fabien@symfony.com>
20  * @author Robin Chalas <robin.chalas@gmail.com>
21  */
22 class AddValidatorInitializersPass implements CompilerPassInterface
23 {
24     private $builderService;
25     private $initializerTag;
26
27     public function __construct($builderService = 'validator.builder', $initializerTag = 'validator.initializer')
28     {
29         $this->builderService = $builderService;
30         $this->initializerTag = $initializerTag;
31     }
32
33     public function process(ContainerBuilder $container)
34     {
35         if (!$container->hasDefinition($this->builderService)) {
36             return;
37         }
38
39         $initializers = array();
40         foreach ($container->findTaggedServiceIds($this->initializerTag, true) as $id => $attributes) {
41             $initializers[] = new Reference($id);
42         }
43
44         $container->getDefinition($this->builderService)->addMethodCall('addObjectInitializers', array($initializers));
45     }
46 }