class ResolveServiceSubscribersPass
Compiler pass to inject their service locator to service subscribers.
@author Nicolas Grekas <p@tchwork.com>
Hierarchy
- class \Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
- class \Symfony\Component\DependencyInjection\Compiler\ResolveServiceSubscribersPass extends \Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass
Expanded class hierarchy of ResolveServiceSubscribersPass
File
-
vendor/
symfony/ dependency-injection/ Compiler/ ResolveServiceSubscribersPass.php, line 24
Namespace
Symfony\Component\DependencyInjection\CompilerView source
class ResolveServiceSubscribersPass extends AbstractRecursivePass {
protected bool $skipScalars = true;
private ?string $serviceLocator = null;
protected function processValue(mixed $value, bool $isRoot = false) : mixed {
if ($value instanceof Reference && $this->serviceLocator && \in_array((string) $value, [
ContainerInterface::class,
ServiceProviderInterface::class,
], true)) {
return new Reference($this->serviceLocator);
}
if (!$value instanceof 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;
}
}
}