rector/vendor/symfony/dependency-injection/Compiler/ResolveServiceSubscribersPass.php
Tomas Votruba a23b777a9a Updated Rector to commit 3a96b9097d6fbc29085210f2d85dd5d95755ef31
3a96b9097d [DeadCode] Skip fluent return  on RemoveEmptyMethodCallRector (#521)
2021-07-27 11:16:44 +00:00

49 lines
2.1 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace RectorPrefix20210727\Symfony\Component\DependencyInjection\Compiler;
use RectorPrefix20210727\Psr\Container\ContainerInterface;
use RectorPrefix20210727\Symfony\Component\DependencyInjection\Definition;
use RectorPrefix20210727\Symfony\Component\DependencyInjection\Reference;
use RectorPrefix20210727\Symfony\Contracts\Service\ServiceProviderInterface;
/**
* Compiler pass to inject their service locator to service subscribers.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class ResolveServiceSubscribersPass extends \RectorPrefix20210727\Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass
{
private $serviceLocator;
/**
* @param bool $isRoot
*/
protected function processValue($value, $isRoot = \false)
{
if ($value instanceof \RectorPrefix20210727\Symfony\Component\DependencyInjection\Reference && $this->serviceLocator && \in_array((string) $value, [\RectorPrefix20210727\Psr\Container\ContainerInterface::class, \RectorPrefix20210727\Symfony\Contracts\Service\ServiceProviderInterface::class], \true)) {
return new \RectorPrefix20210727\Symfony\Component\DependencyInjection\Reference($this->serviceLocator);
}
if (!$value instanceof \RectorPrefix20210727\Symfony\Component\DependencyInjection\Definition) {
return parent::processValue($value, $isRoot);
}
$serviceLocator = $this->serviceLocator;
$this->serviceLocator = null;
if ($value->hasTag('container.service_subscriber.locator')) {
$this->serviceLocator = $value->getTag('container.service_subscriber.locator')[0]['id'];
$value->clearTag('container.service_subscriber.locator');
}
try {
return parent::processValue($value);
} finally {
$this->serviceLocator = $serviceLocator;
}
}
}