bde9433690f95dc2756c540dce471b859ca1864d
[yaffs-website] / vendor / symfony / dependency-injection / Compiler / ResolveServiceSubscribersPass.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\DependencyInjection\Compiler;
13
14 use Psr\Container\ContainerInterface;
15 use Symfony\Component\DependencyInjection\Definition;
16 use Symfony\Component\DependencyInjection\Reference;
17
18 /**
19  * Compiler pass to inject their service locator to service subscribers.
20  *
21  * @author Nicolas Grekas <p@tchwork.com>
22  */
23 class ResolveServiceSubscribersPass extends AbstractRecursivePass
24 {
25     private $serviceLocator;
26
27     protected function processValue($value, $isRoot = false)
28     {
29         if ($value instanceof Reference && $this->serviceLocator && ContainerInterface::class === $this->container->normalizeId($value)) {
30             return new Reference($this->serviceLocator);
31         }
32
33         if (!$value instanceof Definition) {
34             return parent::processValue($value, $isRoot);
35         }
36
37         $serviceLocator = $this->serviceLocator;
38         $this->serviceLocator = $value->hasTag('container.service_subscriber.locator') ? $value->getTag('container.service_subscriber.locator')[0]['id'] : null;
39
40         try {
41             return parent::processValue($value);
42         } finally {
43             $this->serviceLocator = $serviceLocator;
44         }
45     }
46 }