$container =
new ContainerBuilder();
$subscriber =
new class() implements ServiceSubscriberInterface
{ public static function getSubscribedServices(): array
{ return [ new SubscribedService('tagged.iterator', 'iterable', attributes:
new TaggedIterator('tag'
)),
new SubscribedService('tagged.locator', PsrContainerInterface::
class, attributes:
new TaggedLocator('tag'
)),
new SubscribedService('autowired', 'stdClass', attributes:
new Autowire(service: 'service.id'
)),
new SubscribedService('autowired.nullable', 'stdClass', nullable: true, attributes:
new Autowire(service: 'service.id'
)),
new SubscribedService('autowired.parameter', 'string', attributes:
new Autowire('%parameter.1%'
)),
new SubscribedService('autowire.decorated', \stdClass::
class, attributes:
new AutowireDecorated()),
new SubscribedService('target', \stdClass::
class, attributes:
new Target('someTarget'
)),
];
} };
$container->
setParameter('parameter.1', 'foobar'
);
$container->
register('foo',
$subscriber::
class) ->
addMethodCall('setContainer',
[new Reference(PsrContainerInterface::
class)]) ->
addTag('container.service_subscriber'
);
(new RegisterServiceSubscribersPass())->
process($container);
(