Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection\Compiler; Chris@14: Chris@14: use Psr\Container\ContainerInterface; Chris@14: use Symfony\Component\DependencyInjection\Definition; Chris@14: use Symfony\Component\DependencyInjection\Reference; Chris@14: Chris@14: /** Chris@14: * Compiler pass to inject their service locator to service subscribers. Chris@14: * Chris@14: * @author Nicolas Grekas
Chris@14: */ Chris@14: class ResolveServiceSubscribersPass extends AbstractRecursivePass Chris@14: { Chris@14: private $serviceLocator; Chris@14: Chris@14: protected function processValue($value, $isRoot = false) Chris@14: { Chris@14: if ($value instanceof Reference && $this->serviceLocator && ContainerInterface::class === $this->container->normalizeId($value)) { Chris@14: return new Reference($this->serviceLocator); Chris@14: } Chris@14: Chris@14: if (!$value instanceof Definition) { Chris@14: return parent::processValue($value, $isRoot); Chris@14: } Chris@14: Chris@14: $serviceLocator = $this->serviceLocator; Chris@16: $this->serviceLocator = null; Chris@16: Chris@16: if ($value->hasTag('container.service_subscriber.locator')) { Chris@16: $this->serviceLocator = $value->getTag('container.service_subscriber.locator')[0]['id']; Chris@16: $value->clearTag('container.service_subscriber.locator'); Chris@16: } Chris@14: Chris@14: try { Chris@14: return parent::processValue($value); Chris@14: } finally { Chris@14: $this->serviceLocator = $serviceLocator; Chris@14: } Chris@14: } Chris@14: }