Skip to content

Commit 3a51ec2

Browse files
committed
upgrade event-sourcing to 3.12
1 parent 2c07f18 commit 3a51ec2

5 files changed

Lines changed: 172 additions & 25 deletions

File tree

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",
22-
"patchlevel/event-sourcing": "^3.11.0",
22+
"patchlevel/event-sourcing": "dev-DCB as 3.12.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",

composer.lock

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

src/DependencyInjection/Configuration.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66

77
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
88
use Symfony\Component\Config\Definition\ConfigurationInterface;
9+
use Throwable;
910

1011
/**
1112
* @psalm-type Config = array{
1213
* event_bus: array{enabled: bool, type: string, service: string},
13-
* command_bus: array{enabled: bool, service: string},
14+
* command_bus: array{
15+
* enabled: bool,
16+
* service: string,
17+
* instant_retry: array{
18+
* default_max_retries: positive-int|0,
19+
* default_exceptions: list<class-string<Throwable>>
20+
* },
21+
* },
1422
* query_bus: array{enabled: bool, service: string},
1523
* subscription: array{
1624
* store: array{type: string, service: string|null},
@@ -69,6 +77,7 @@
6977
* },
7078
* clock: array{freeze: ?string, service: ?string},
7179
* aggregate_handlers: array{enabled: bool, bus: string|null},
80+
* dcb: array{enabled: bool},
7281
* }
7382
*/
7483
final class Configuration implements ConfigurationInterface
@@ -96,7 +105,7 @@ public function getConfigTreeBuilder(): TreeBuilder
96105
->addDefaultsIfNotSet()
97106
->children()
98107
->enumNode('type')
99-
->values(['dbal_aggregate', 'dbal_stream', 'in_memory', 'custom'])
108+
->values(['dbal_aggregate', 'dbal_stream', 'dbal_taggable', 'in_memory', 'custom'])
100109
->defaultValue('dbal_aggregate')
101110
->end()
102111
->scalarNode('service')->defaultNull()->end()
@@ -108,7 +117,7 @@ public function getConfigTreeBuilder(): TreeBuilder
108117
->addDefaultsIfNotSet()
109118
->children()
110119
->enumNode('type')
111-
->values(['dbal_aggregate', 'dbal_stream', 'in_memory', 'custom'])
120+
->values(['dbal_aggregate', 'dbal_stream', 'dbal_taggable', 'in_memory', 'custom'])
112121
->end()
113122
->scalarNode('service')->defaultNull()->end()
114123
->arrayNode('options')->variablePrototype()->end()->end()
@@ -302,6 +311,18 @@ public function getConfigTreeBuilder(): TreeBuilder
302311
->children()
303312
->scalarNode('service')->isRequired()->end()
304313
->booleanNode('register_aggregate_handlers')->defaultTrue()->end()
314+
->arrayNode('instant_retry')
315+
->addDefaultsIfNotSet()
316+
->children()
317+
->integerNode('default_max_retries')
318+
->defaultValue(3)
319+
->end()
320+
->arrayNode('default_exceptions')
321+
->defaultValue([])
322+
->scalarPrototype()->end()
323+
->end()
324+
->end()
325+
->end()
305326
->end()
306327
->end()
307328

@@ -313,6 +334,10 @@ public function getConfigTreeBuilder(): TreeBuilder
313334
->end()
314335
->end()
315336

337+
->arrayNode('dcb')
338+
->canBeEnabled()
339+
->end()
340+
316341
->arrayNode('aggregate_handlers')
317342
->canBeEnabled()
318343
->addDefaultsIfNotSet()

src/DependencyInjection/PatchlevelEventSourcingExtension.php

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Patchlevel\EventSourcing\Clock\FrozenClock;
2626
use Patchlevel\EventSourcing\Clock\SystemClock;
2727
use Patchlevel\EventSourcing\CommandBus\CommandBus;
28+
use Patchlevel\EventSourcing\CommandBus\InstantRetryCommandBus;
2829
use Patchlevel\EventSourcing\Console\Command\DatabaseCreateCommand;
2930
use Patchlevel\EventSourcing\Console\Command\DatabaseDropCommand;
3031
use Patchlevel\EventSourcing\Console\Command\DebugCommand;
@@ -44,6 +45,12 @@
4445
use Patchlevel\EventSourcing\Console\Command\WatchCommand;
4546
use Patchlevel\EventSourcing\Console\DoctrineHelper;
4647
use Patchlevel\EventSourcing\Cryptography\DoctrineCipherKeyStore;
48+
use Patchlevel\EventSourcing\DCB\AttributeEventTagExtractor;
49+
use Patchlevel\EventSourcing\DCB\DecisionModelBuilder;
50+
use Patchlevel\EventSourcing\DCB\EventAppender;
51+
use Patchlevel\EventSourcing\DCB\EventTagExtractor;
52+
use Patchlevel\EventSourcing\DCB\StoreDecisionModelBuilder;
53+
use Patchlevel\EventSourcing\DCB\StoreEventAppender;
4754
use Patchlevel\EventSourcing\EventBus\AttributeListenerProvider;
4855
use Patchlevel\EventSourcing\EventBus\Consumer;
4956
use Patchlevel\EventSourcing\EventBus\DefaultConsumer;
@@ -69,6 +76,7 @@
6976
use Patchlevel\EventSourcing\QueryBus\QueryBus;
7077
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
7178
use Patchlevel\EventSourcing\Repository\MessageDecorator\ChainMessageDecorator;
79+
use Patchlevel\EventSourcing\Repository\MessageDecorator\EventTagDecorator;
7280
use Patchlevel\EventSourcing\Repository\MessageDecorator\MessageDecorator;
7381
use Patchlevel\EventSourcing\Repository\MessageDecorator\SplitStreamDecorator;
7482
use Patchlevel\EventSourcing\Repository\RepositoryManager;
@@ -95,6 +103,7 @@
95103
use Patchlevel\EventSourcing\Store\Store;
96104
use Patchlevel\EventSourcing\Store\StreamDoctrineDbalStore;
97105
use Patchlevel\EventSourcing\Store\StreamReadOnlyStore;
106+
use Patchlevel\EventSourcing\Store\TaggableDoctrineDbalStore;
98107
use Patchlevel\EventSourcing\Subscription\Engine\CatchUpSubscriptionEngine;
99108
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
100109
use Patchlevel\EventSourcing\Subscription\Engine\GapResolverStoreMessageLoader;
@@ -189,6 +198,7 @@ public function load(array $configs, ContainerBuilder $container): void
189198
$this->configureMigration($config, $container);
190199
$this->configureValueResolver($container);
191200
$this->configureStoreMigration($config, $container);
201+
$this->configureDCB($config, $container);
192202
}
193203

194204
/** @param Config $config */
@@ -231,6 +241,9 @@ private function configureSerializer(array $config, ContainerBuilder $container)
231241
]);
232242

233243
$container->setAlias(HeadersSerializer::class, DefaultHeadersSerializer::class);
244+
245+
$container->register(AttributeEventTagExtractor::class);
246+
$container->setAlias(EventTagExtractor::class, AttributeEventTagExtractor::class);
234247
}
235248

236249
/** @param Config $config */
@@ -246,7 +259,14 @@ private function configureCommandBus(array $config, ContainerBuilder $container)
246259
new Reference($config['command_bus']['service']),
247260
]);
248261

249-
$container->setAlias(CommandBus::class, SymfonyCommandBus::class);
262+
$container->register(InstantRetryCommandBus::class)
263+
->setArguments([
264+
new Reference(SymfonyCommandBus::class),
265+
$config['command_bus']['instant_retry']['default_max_retries'],
266+
$config['command_bus']['instant_retry']['default_exceptions'],
267+
]);
268+
269+
$container->setAlias(CommandBus::class, InstantRetryCommandBus::class);
250270

251271
$container->setParameter(
252272
'patchlevel_event_sourcing.aggregate_handlers.bus',
@@ -621,6 +641,10 @@ private function configureMessageDecorator(ContainerBuilder $container): void
621641
->setArguments([new Reference(EventMetadataFactory::class)])
622642
->addTag('event_sourcing.message_decorator');
623643

644+
$container->register(EventTagDecorator::class)
645+
->setArguments([new Reference(EventTagExtractor::class)])
646+
->addTag('event_sourcing.message_decorator');
647+
624648
$container->registerForAutoconfiguration(MessageDecorator::class)
625649
->addTag('event_sourcing.message_decorator');
626650

@@ -748,6 +772,26 @@ private function configureStore(array $config, ContainerBuilder $container): voi
748772
return;
749773
}
750774

775+
if ($config['store']['type'] === 'dbal_taggable') {
776+
$container->register(TaggableDoctrineDbalStore::class)
777+
->setArguments([
778+
new Reference('event_sourcing.dbal_connection'),
779+
new Reference(EventSerializer::class),
780+
new Reference(HeadersSerializer::class),
781+
new Reference('event_sourcing.clock'),
782+
$config['store']['options'],
783+
])
784+
->addTag('event_sourcing.doctrine_schema_configurator');
785+
786+
$container->setAlias(Store::class, TaggableDoctrineDbalStore::class);
787+
788+
if ($config['store']['read_only']) {
789+
throw new InvalidArgumentException('Taggable store does not support read only');
790+
}
791+
792+
return;
793+
}
794+
751795
throw new InvalidArgumentException(sprintf('Unknown store type "%s"', $config['store']['type']));
752796
}
753797

@@ -814,6 +858,20 @@ private function configureStoreMigration(array $config, ContainerBuilder $contai
814858
return;
815859
}
816860

861+
if ($config['store']['migrate_to_new_store']['type'] === 'dbal_taggable') {
862+
$container->register($id, TaggableDoctrineDbalStore::class)
863+
->setArguments([
864+
new Reference('event_sourcing.dbal_connection'),
865+
new Reference(EventSerializer::class),
866+
new Reference(HeadersSerializer::class),
867+
new Reference('event_sourcing.clock'),
868+
$config['store']['migrate_to_new_store']['options'],
869+
])
870+
->addTag('event_sourcing.doctrine_schema_configurator');
871+
872+
return;
873+
}
874+
817875
throw new InvalidArgumentException(sprintf('Unknown store type "%s"', $config['store']['type']));
818876
}
819877

@@ -1165,6 +1223,31 @@ private function configureCryptography(array $config, ContainerBuilder $containe
11651223
$container->setAlias(PayloadCryptographer::class, PersonalDataPayloadCryptographer::class);
11661224
}
11671225

1226+
/** @param Config $config */
1227+
private function configureDCB(array $config, ContainerBuilder $container): void
1228+
{
1229+
if (!$config['dcb']['enabled']) {
1230+
return;
1231+
}
1232+
1233+
if ($config['store']['type'] !== 'dbal_taggable') {
1234+
throw new InvalidArgumentException(
1235+
'DCB requires a taggable store, please use "dbal_taggable" as store type.',
1236+
);
1237+
}
1238+
1239+
$container->register(StoreDecisionModelBuilder::class)
1240+
->setArguments([new Reference(TaggableDoctrineDbalStore::class)]);
1241+
$container->setAlias(DecisionModelBuilder::class, StoreDecisionModelBuilder::class);
1242+
1243+
$container->register(StoreEventAppender::class)
1244+
->setArguments([
1245+
new Reference(TaggableDoctrineDbalStore::class),
1246+
new Reference(EventTagExtractor::class),
1247+
]);
1248+
$container->setAlias(EventAppender::class, StoreEventAppender::class);
1249+
}
1250+
11681251
private function configureValueResolver(ContainerBuilder $container): void
11691252
{
11701253
$container->register(AggregateRootIdValueResolver::class)

0 commit comments

Comments
 (0)