Skip to content

Commit a2d0e74

Browse files
committed
Fix
1 parent 87fb6d9 commit a2d0e74

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
],
2020
"require": {
2121
"php": "~8.2.0 || ~8.3.0",
22-
"patchlevel/event-sourcing": "^3.8.0",
22+
"patchlevel/event-sourcing": "^3.9.0",
2323
"symfony/cache": "^6.4.0|^7.0.0",
2424
"symfony/config": "^6.4.0|^7.0.0",
2525
"symfony/console": "^6.4.1|^7.0.1",
2626
"symfony/dependency-injection": "^6.4.1|^7.0.1",
27+
"symfony/event-dispatcher": "^6.4.1|^7.0.1",
2728
"symfony/finder": "^6.4.0|^7.0.0",
2829
"symfony/http-kernel": "^6.4.1|^7.0.1",
2930
"symfony/messenger": "^6.4.0|^7.0.0"

composer.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DependencyInjection/PatchlevelEventSourcingExtension.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
use Patchlevel\EventSourcingBundle\EventBus\SymfonyEventBus;
114114
use Patchlevel\EventSourcingBundle\RequestListener\AutoSetupListener;
115115
use Patchlevel\EventSourcingBundle\RequestListener\SubscriptionRebuildAfterFileChangeListener;
116+
use Patchlevel\EventSourcingBundle\Subscription\ResetServicesListener;
116117
use Patchlevel\EventSourcingBundle\Subscription\StaticInMemorySubscriptionStoreFactory;
117118
use Patchlevel\EventSourcingBundle\ValueResolver\AggregateRootIdValueResolver;
118119
use Patchlevel\Hydrator\Cryptography\Cipher\Cipher;
@@ -126,6 +127,7 @@
126127
use Patchlevel\Hydrator\Metadata\AttributeMetadataFactory;
127128
use Patchlevel\Hydrator\Metadata\MetadataFactory;
128129
use Patchlevel\Hydrator\MetadataHydrator;
130+
use Patchlevel\Worker\Event\WorkerRunningEvent;
129131
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
130132
use Symfony\Component\DependencyInjection\ChildDefinition;
131133
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -375,6 +377,15 @@ static function (ChildDefinition $definition): void {
375377

376378
$container->setAlias(SubscriptionEngine::class, DefaultSubscriptionEngine::class);
377379

380+
$container->register(ResetServicesListener::class)
381+
->setArguments([
382+
new Reference('services_resetter'),
383+
])
384+
->addTag('kernel.event_listener', [
385+
'event' => WorkerRunningEvent::class,
386+
'method' => 'onWorkerRunningEvent',
387+
]);
388+
378389
if ($config['subscription']['throw_on_error']['enabled']) {
379390
$container->register(ThrowOnErrorSubscriptionEngine::class)
380391
->setDecoratedService(SubscriptionEngine::class)
@@ -773,13 +784,15 @@ private function configureCommands(ContainerBuilder $container): void
773784
$container->register(SubscriptionBootCommand::class)
774785
->setArguments([
775786
new Reference(SubscriptionEngine::class),
787+
new Reference('event_dispatcher', ContainerInterface::NULL_ON_INVALID_REFERENCE),
776788
])
777789
->addTag('console.command');
778790

779791
$container->register(SubscriptionRunCommand::class)
780792
->setArguments([
781793
new Reference(SubscriptionEngine::class),
782794
new Reference(Store::class),
795+
new Reference('event_dispatcher', ContainerInterface::NULL_ON_INVALID_REFERENCE),
783796
])
784797
->addTag('console.command');
785798

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcingBundle\Subscription;
6+
7+
use Patchlevel\Worker\Event\WorkerRunningEvent;
8+
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
9+
10+
final readonly class ResetServicesListener
11+
{
12+
public function __construct(private ServicesResetter $servicesResetter)
13+
{
14+
}
15+
16+
public function onWorkerRunningEvent(WorkerRunningEvent $event): void
17+
{
18+
$this->servicesResetter->reset();
19+
}
20+
}

tests/Unit/PatchlevelEventSourcingBundleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
use Patchlevel\EventSourcingBundle\DependencyInjection\PatchlevelEventSourcingExtension;
7474
use Patchlevel\EventSourcingBundle\EventBus\SymfonyEventBus;
7575
use Patchlevel\EventSourcingBundle\PatchlevelEventSourcingBundle;
76+
use Patchlevel\EventSourcingBundle\Subscription\ResetServicesListener;
7677
use Patchlevel\EventSourcingBundle\Tests\Fixtures\CreateProfile;
7778
use Patchlevel\EventSourcingBundle\Tests\Fixtures\CustomHeader;
7879
use Patchlevel\EventSourcingBundle\Tests\Fixtures\DummyArgumentResolver;
@@ -99,6 +100,7 @@
99100
use Symfony\Component\DependencyInjection\ContainerBuilder;
100101
use Symfony\Component\DependencyInjection\Definition;
101102
use Symfony\Component\DependencyInjection\Reference;
103+
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
102104
use Symfony\Component\Messenger\MessageBusInterface;
103105

104106
final class PatchlevelEventSourcingBundleTest extends TestCase
@@ -1183,6 +1185,7 @@ public function testFullBuild(): void
11831185
self::assertInstanceOf(RepositoryManager::class, $container->get(RepositoryManager::class));
11841186
self::assertInstanceOf(EventRegistry::class, $container->get(EventRegistry::class));
11851187
self::assertInstanceOf(DoctrineSubscriptionStore::class, $container->get(SubscriptionStore::class));
1188+
self::assertInstanceOf(ResetServicesListener::class, $container->get(ResetServicesListener::class));
11861189
}
11871190

11881191
public function testNamedRepository(): void
@@ -1221,6 +1224,7 @@ private function compileContainer(ContainerBuilder $container, array $config): v
12211224
$container->set('event.bus', $this->prophesize(MessageBusInterface::class)->reveal());
12221225
$container->set('cache.default', $this->prophesize(CacheItemPoolInterface::class)->reveal());
12231226
$container->set('event_dispatcher', $this->prophesize(EventDispatcherInterface::class)->reveal());
1227+
$container->set('services_resetter', $this->prophesize(ServicesResetter::class)->reveal());
12241228
$container->set(LoggerInterface::class, $this->prophesize(LoggerInterface::class)->reveal());
12251229

12261230
$extension = new PatchlevelEventSourcingExtension();

0 commit comments

Comments
 (0)