annotate vendor/symfony/dependency-injection/Compiler/ResolveServiceSubscribersPass.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children c2387f117808
rev   line source
Chris@14 1 <?php
Chris@14 2
Chris@14 3 /*
Chris@14 4 * This file is part of the Symfony package.
Chris@14 5 *
Chris@14 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@14 7 *
Chris@14 8 * For the full copyright and license information, please view the LICENSE
Chris@14 9 * file that was distributed with this source code.
Chris@14 10 */
Chris@14 11
Chris@14 12 namespace Symfony\Component\DependencyInjection\Compiler;
Chris@14 13
Chris@14 14 use Psr\Container\ContainerInterface;
Chris@14 15 use Symfony\Component\DependencyInjection\Definition;
Chris@14 16 use Symfony\Component\DependencyInjection\Reference;
Chris@14 17
Chris@14 18 /**
Chris@14 19 * Compiler pass to inject their service locator to service subscribers.
Chris@14 20 *
Chris@14 21 * @author Nicolas Grekas <p@tchwork.com>
Chris@14 22 */
Chris@14 23 class ResolveServiceSubscribersPass extends AbstractRecursivePass
Chris@14 24 {
Chris@14 25 private $serviceLocator;
Chris@14 26
Chris@14 27 protected function processValue($value, $isRoot = false)
Chris@14 28 {
Chris@14 29 if ($value instanceof Reference && $this->serviceLocator && ContainerInterface::class === $this->container->normalizeId($value)) {
Chris@14 30 return new Reference($this->serviceLocator);
Chris@14 31 }
Chris@14 32
Chris@14 33 if (!$value instanceof Definition) {
Chris@14 34 return parent::processValue($value, $isRoot);
Chris@14 35 }
Chris@14 36
Chris@14 37 $serviceLocator = $this->serviceLocator;
Chris@14 38 $this->serviceLocator = $value->hasTag('container.service_subscriber.locator') ? $value->getTag('container.service_subscriber.locator')[0]['id'] : null;
Chris@14 39
Chris@14 40 try {
Chris@14 41 return parent::processValue($value);
Chris@14 42 } finally {
Chris@14 43 $this->serviceLocator = $serviceLocator;
Chris@14 44 }
Chris@14 45 }
Chris@14 46 }