Skip to content

Commit 3ce3e83

Browse files
committed
make EventSubscribersCollection implement ServiceFactory so it can be simply register()ed
1 parent 53d10e3 commit 3ce3e83

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/EventDispatcher/EventSubscribersCollection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use RuntimeException;
99
use Symfony\Component\EventDispatcher\EventDispatcher;
1010
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11+
use WonderNetwork\SlimKernel\ServiceFactory;
12+
use WonderNetwork\SlimKernel\ServicesBuilder;
1113
use function DI\decorate;
1214

13-
final readonly class EventSubscribersCollection {
15+
final readonly class EventSubscribersCollection implements ServiceFactory {
1416
public static function start(): self {
1517
return new self([]);
1618
}
@@ -69,4 +71,8 @@ public function register(): iterable {
6971
->addLazyListeners($dispatcher, $container),
7072
);
7173
}
74+
75+
public function __invoke(ServicesBuilder $builder): iterable {
76+
yield from $this->register();
77+
}
7278
}

tests/ConsoleLogger/ConsoleLoggerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public function testConsoleLogger(): void {
4242
return $logger;
4343
},
4444
ConsoleHandlerEventSubscriber::class => autowire(),
45-
...EventSubscribersCollection::start()
46-
->add(ConsoleHandlerEventSubscriber::class)
47-
->register(),
4845
],
4946
)
47+
->register(
48+
EventSubscribersCollection::start()
49+
->add(ConsoleHandlerEventSubscriber::class),
50+
)
5051
->register(
5152
new SymfonyConsoleServiceFactory(
5253
path: '/src/*Command.php',

0 commit comments

Comments
 (0)