Skip to content

Commit b9bdc66

Browse files
committed
add event sourcing 3.18 features
1 parent 75f27cd commit b9bdc66

8 files changed

Lines changed: 356 additions & 219 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ phpunit.xml
66
phpstan.neon
77
infection.html
88
infection.log
9+
/docs_php

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
22-
"patchlevel/event-sourcing": "^3.13.0",
22+
"patchlevel/event-sourcing": "^3.18.0",
2323
"symfony/cache": "^6.4.0 || ^7.0.0 || ^8.0.0",
2424
"symfony/config": "^6.4.0 || ^7.0.0 || ^8.0.0",
2525
"symfony/console": "^6.4.1 || ^7.0.1 || ^8.0.0",

composer.lock

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

src/Command/StoreMigrateCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use function count;
1919

20+
/** @deprecated since version 3.15.0, to be removed in 4.0.0. Use the StoreMigrateCommand from the patchlevel/event-sourcing package instead. */
2021
#[AsCommand(
2122
'event-sourcing:store:migrate',
2223
'migrate events from one store to another',
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcingBundle\DependencyInjection;
6+
7+
use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DbalCleanupTaskHandler;
8+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9+
use Symfony\Component\DependencyInjection\ContainerBuilder;
10+
use Symfony\Component\DependencyInjection\Reference;
11+
12+
final class DoctrineCleanupCompilerPass implements CompilerPassInterface
13+
{
14+
public function process(ContainerBuilder $container): void
15+
{
16+
if ($container->has('doctrine')) {
17+
$container->register(DbalCleanupTaskHandler::class, DbalCleanupTaskHandler::class)
18+
->setArguments([
19+
new Reference('doctrine'),
20+
])
21+
->addTag('event_sourcing.cleanup_task_handler');
22+
} elseif ($container->has('event_sourcing.dbal_public_connection')) {
23+
$container->register(DbalCleanupTaskHandler::class, DbalCleanupTaskHandler::class)
24+
->setArguments([
25+
new Reference('event_sourcing.dbal_public_connection'),
26+
])
27+
->addTag('event_sourcing.cleanup_task_handler');
28+
}
29+
}
30+
}

src/DependencyInjection/PatchlevelEventSourcingExtension.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
use Patchlevel\EventSourcing\Console\Command\SchemaUpdateCommand;
3333
use Patchlevel\EventSourcing\Console\Command\ShowAggregateCommand;
3434
use Patchlevel\EventSourcing\Console\Command\ShowCommand;
35+
use Patchlevel\EventSourcing\Console\Command\StoreMigrateCommand;
3536
use Patchlevel\EventSourcing\Console\Command\SubscriptionBootCommand;
3637
use Patchlevel\EventSourcing\Console\Command\SubscriptionPauseCommand;
3738
use Patchlevel\EventSourcing\Console\Command\SubscriptionReactivateCommand;
39+
use Patchlevel\EventSourcing\Console\Command\SubscriptionRefreshCommand;
3840
use Patchlevel\EventSourcing\Console\Command\SubscriptionRemoveCommand;
3941
use Patchlevel\EventSourcing\Console\Command\SubscriptionRunCommand;
4042
use Patchlevel\EventSourcing\Console\Command\SubscriptionSetupCommand;
@@ -94,6 +96,9 @@
9496
use Patchlevel\EventSourcing\Store\Store;
9597
use Patchlevel\EventSourcing\Store\StreamDoctrineDbalStore;
9698
use Patchlevel\EventSourcing\Store\StreamReadOnlyStore;
99+
use Patchlevel\EventSourcing\Subscription\Cleanup\Cleaner;
100+
use Patchlevel\EventSourcing\Subscription\Cleanup\CleanupTaskHandler;
101+
use Patchlevel\EventSourcing\Subscription\Cleanup\DefaultCleaner;
97102
use Patchlevel\EventSourcing\Subscription\Engine\CatchUpSubscriptionEngine;
98103
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
99104
use Patchlevel\EventSourcing\Subscription\Engine\GapResolverStoreMessageLoader;
@@ -116,7 +121,6 @@
116121
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberHelper;
117122
use Patchlevel\EventSourcingBundle\Attribute\AsListener;
118123
use Patchlevel\EventSourcingBundle\Clock\FrozenClockFactory;
119-
use Patchlevel\EventSourcingBundle\Command\StoreMigrateCommand;
120124
use Patchlevel\EventSourcingBundle\CommandBus\SymfonyCommandBus;
121125
use Patchlevel\EventSourcingBundle\DataCollector\EventSourcingCollector;
122126
use Patchlevel\EventSourcingBundle\DataCollector\MessageCollectorEventBus;
@@ -516,13 +520,24 @@ static function (ChildDefinition $definition): void {
516520

517521
$container->setAlias(SubscriberAccessorRepository::class, MetadataSubscriberAccessorRepository::class);
518522

523+
$container->registerForAutoconfiguration(CleanupTaskHandler::class)
524+
->addTag('event_sourcing.cleanup_task_handler');
525+
526+
$container->register(DefaultCleaner::class)
527+
->setArguments([
528+
new TaggedIteratorArgument('event_sourcing.cleanup_task_handler'),
529+
]);
530+
531+
$container->setAlias(Cleaner::class, DefaultCleaner::class);
532+
519533
$container->register(DefaultSubscriptionEngine::class)
520534
->setArguments([
521535
new Reference(MessageLoader::class),
522536
new Reference(SubscriptionStore::class),
523537
new Reference(SubscriberAccessorRepository::class),
524538
new Reference(RetryStrategyRepository::class),
525539
new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE),
540+
new Reference(Cleaner::class),
526541
])
527542
->addTag('monolog.logger', ['channel' => 'event_sourcing']);
528543

@@ -981,6 +996,12 @@ private function configureCommands(ContainerBuilder $container): void
981996
new Reference(SubscriptionEngine::class),
982997
])
983998
->addTag('console.command');
999+
1000+
$container->register(SubscriptionRefreshCommand::class)
1001+
->setArguments([
1002+
new Reference(SubscriptionEngine::class),
1003+
])
1004+
->addTag('console.command');
9841005
}
9851006

9861007
/** @param Config $config */

src/PatchlevelEventSourcingBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Patchlevel\EventSourcingBundle;
66

77
use Patchlevel\EventSourcingBundle\DependencyInjection\CommandHandlerCompilerPass;
8+
use Patchlevel\EventSourcingBundle\DependencyInjection\DoctrineCleanupCompilerPass;
89
use Patchlevel\EventSourcingBundle\DependencyInjection\HandlerServiceLocatorCompilerPass;
910
use Patchlevel\EventSourcingBundle\DependencyInjection\QueryHandlerCompilerPass;
1011
use Patchlevel\EventSourcingBundle\DependencyInjection\RepositoryCompilerPass;
@@ -23,5 +24,6 @@ public function build(ContainerBuilder $container): void
2324
$container->addCompilerPass(new QueryHandlerCompilerPass(), priority: 100);
2425
$container->addCompilerPass(new HandlerServiceLocatorCompilerPass(), priority: -100);
2526
$container->addCompilerPass(new TranslatorCompilerPass());
27+
$container->addCompilerPass(new DoctrineCleanupCompilerPass());
2628
}
2729
}

tests/Unit/PatchlevelEventSourcingBundleTest.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
1111
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
1212
use Doctrine\Migrations\Tools\Console\Command\StatusCommand;
13+
use Doctrine\Persistence\ManagerRegistry;
1314
use InvalidArgumentException;
1415
use Patchlevel\EventSourcing\Attribute\Aggregate;
1516
use Patchlevel\EventSourcing\Attribute\Event;
@@ -26,9 +27,11 @@
2627
use Patchlevel\EventSourcing\Console\Command\SchemaUpdateCommand;
2728
use Patchlevel\EventSourcing\Console\Command\ShowAggregateCommand;
2829
use Patchlevel\EventSourcing\Console\Command\ShowCommand;
30+
use Patchlevel\EventSourcing\Console\Command\StoreMigrateCommand;
2931
use Patchlevel\EventSourcing\Console\Command\SubscriptionBootCommand;
3032
use Patchlevel\EventSourcing\Console\Command\SubscriptionPauseCommand;
3133
use Patchlevel\EventSourcing\Console\Command\SubscriptionReactivateCommand;
34+
use Patchlevel\EventSourcing\Console\Command\SubscriptionRefreshCommand;
3235
use Patchlevel\EventSourcing\Console\Command\SubscriptionRemoveCommand;
3336
use Patchlevel\EventSourcing\Console\Command\SubscriptionRunCommand;
3437
use Patchlevel\EventSourcing\Console\Command\SubscriptionSetupCommand;
@@ -67,6 +70,9 @@
6770
use Patchlevel\EventSourcing\Store\StreamDoctrineDbalStore;
6871
use Patchlevel\EventSourcing\Store\StreamReadOnlyStore;
6972
use Patchlevel\EventSourcing\Store\StreamStore;
73+
use Patchlevel\EventSourcing\Subscription\Cleanup\Cleaner;
74+
use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DbalCleanupTaskHandler;
75+
use Patchlevel\EventSourcing\Subscription\Cleanup\DefaultCleaner;
7076
use Patchlevel\EventSourcing\Subscription\Engine\CatchUpSubscriptionEngine;
7177
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
7278
use Patchlevel\EventSourcing\Subscription\Engine\GapResolverStoreMessageLoader;
@@ -82,8 +88,6 @@
8288
use Patchlevel\EventSourcing\Subscription\Store\InMemorySubscriptionStore;
8389
use Patchlevel\EventSourcing\Subscription\Store\SubscriptionStore;
8490
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
85-
use Patchlevel\EventSourcingBundle\Command\StoreMigrateCommand;
86-
use Patchlevel\EventSourcingBundle\DependencyInjection\Configuration;
8791
use Patchlevel\EventSourcingBundle\DependencyInjection\PatchlevelEventSourcingExtension;
8892
use Patchlevel\EventSourcingBundle\EventBus\SymfonyEventBus;
8993
use Patchlevel\EventSourcingBundle\PatchlevelEventSourcingBundle;
@@ -786,6 +790,60 @@ public function testGapDetectionWithExplicitValues(): void
786790
self::assertInstanceOf(GapResolverStoreMessageLoader::class, $messageLoader);
787791
}
788792

793+
public function testSubscriptionCleanupWithDoctrine(): void
794+
{
795+
$registry = $this->createMock(ManagerRegistry::class);
796+
797+
$container = new ContainerBuilder();
798+
$container->set('doctrine', $registry);
799+
800+
$this->compileContainer(
801+
$container,
802+
[
803+
'patchlevel_event_sourcing' => [
804+
'connection' => [
805+
'service' => 'doctrine.dbal.eventstore_connection',
806+
],
807+
'store' => [
808+
'merge_orm_schema' => true,
809+
],
810+
],
811+
]
812+
);
813+
814+
$definition = $container->getDefinition(DbalCleanupTaskHandler::class);
815+
$tags = $definition->getTag('event_sourcing.cleanup_task_handler');
816+
817+
self::assertCount(1, $tags);
818+
819+
$cleaner = $container->get(Cleaner::class);
820+
self::assertInstanceOf(DefaultCleaner::class, $cleaner);
821+
}
822+
823+
public function testSubscriptionCleanupWithProjectionConnection(): void
824+
{
825+
$container = new ContainerBuilder();
826+
$this->compileContainer(
827+
$container,
828+
[
829+
'patchlevel_event_sourcing' => [
830+
'connection' => [
831+
'url' => 'sqlite3:///:memory:',
832+
'provide_dedicated_connection' => true,
833+
],
834+
],
835+
]
836+
);
837+
838+
$definition = $container->getDefinition(DbalCleanupTaskHandler::class);
839+
$tags = $definition->getTag('event_sourcing.cleanup_task_handler');
840+
841+
self::assertCount(1, $tags);
842+
843+
$cleaner = $container->get(Cleaner::class);
844+
self::assertInstanceOf(DefaultCleaner::class, $cleaner);
845+
}
846+
789847
public function testSnapshotStore(): void
790848
{
791849
$container = new ContainerBuilder();
@@ -1013,6 +1071,7 @@ public function testCommands(): void
10131071
self::assertInstanceOf(SubscriptionSetupCommand::class, $container->get(SubscriptionSetupCommand::class));
10141072
self::assertInstanceOf(SubscriptionStatusCommand::class, $container->get(SubscriptionStatusCommand::class));
10151073
self::assertInstanceOf(SubscriptionTeardownCommand::class, $container->get(SubscriptionTeardownCommand::class));
1074+
self::assertInstanceOf(SubscriptionRefreshCommand::class, $container->get(SubscriptionRefreshCommand::class));
10161075
self::assertInstanceOf(SchemaCreateCommand::class, $container->get(SchemaCreateCommand::class));
10171076
self::assertInstanceOf(SchemaUpdateCommand::class, $container->get(SchemaUpdateCommand::class));
10181077
self::assertInstanceOf(SchemaDropCommand::class, $container->get(SchemaDropCommand::class));

0 commit comments

Comments
 (0)