4545use Patchlevel \EventSourcing \Console \Command \WatchCommand ;
4646use Patchlevel \EventSourcing \Console \DoctrineHelper ;
4747use Patchlevel \EventSourcing \Cryptography \DoctrineCipherKeyStore ;
48+ use Patchlevel \EventSourcing \DecisionModel \DecisionModelBuilder ;
49+ use Patchlevel \EventSourcing \DecisionModel \EventAppender ;
50+ use Patchlevel \EventSourcing \DecisionModel \StoreDecisionModelBuilder ;
51+ use Patchlevel \EventSourcing \DecisionModel \StoreEventAppender ;
4852use Patchlevel \EventSourcing \EventBus \AttributeListenerProvider ;
4953use Patchlevel \EventSourcing \EventBus \Consumer ;
5054use Patchlevel \EventSourcing \EventBus \DefaultConsumer ;
7074use Patchlevel \EventSourcing \QueryBus \QueryBus ;
7175use Patchlevel \EventSourcing \Repository \DefaultRepositoryManager ;
7276use Patchlevel \EventSourcing \Repository \MessageDecorator \ChainMessageDecorator ;
77+ use Patchlevel \EventSourcing \Repository \MessageDecorator \EventTagDecorator ;
7378use Patchlevel \EventSourcing \Repository \MessageDecorator \MessageDecorator ;
7479use Patchlevel \EventSourcing \Repository \MessageDecorator \SplitStreamDecorator ;
7580use Patchlevel \EventSourcing \Repository \RepositoryManager ;
8085use Patchlevel \EventSourcing \Schema \DoctrineSchemaListener ;
8186use Patchlevel \EventSourcing \Schema \DoctrineSchemaProvider ;
8287use Patchlevel \EventSourcing \Schema \SchemaDirector ;
88+ use Patchlevel \EventSourcing \Serializer \AttributeEventTagExtractor ;
8389use Patchlevel \EventSourcing \Serializer \DefaultEventSerializer ;
8490use Patchlevel \EventSourcing \Serializer \Encoder \Encoder ;
8591use Patchlevel \EventSourcing \Serializer \Encoder \JsonEncoder ;
8692use Patchlevel \EventSourcing \Serializer \EventSerializer ;
93+ use Patchlevel \EventSourcing \Serializer \EventTagExtractor ;
8794use Patchlevel \EventSourcing \Serializer \Upcast \Upcaster ;
8895use Patchlevel \EventSourcing \Serializer \Upcast \UpcasterChain ;
8996use Patchlevel \EventSourcing \Snapshot \Adapter \Psr16SnapshotAdapter ;
9097use Patchlevel \EventSourcing \Snapshot \Adapter \Psr6SnapshotAdapter ;
9198use Patchlevel \EventSourcing \Snapshot \DefaultSnapshotStore ;
9299use Patchlevel \EventSourcing \Snapshot \SnapshotStore ;
93100use Patchlevel \EventSourcing \Store \InMemoryStore ;
101+ use Patchlevel \EventSourcing \Store \ReadOnlyStore ;
94102use Patchlevel \EventSourcing \Store \Store ;
95103use Patchlevel \EventSourcing \Store \StreamDoctrineDbalStore ;
96- use Patchlevel \EventSourcing \Store \StreamReadOnlyStore ;
104+ use Patchlevel \EventSourcing \Store \TaggableDoctrineDbalStore ;
97105use Patchlevel \EventSourcing \Subscription \Engine \CatchUpSubscriptionEngine ;
98106use Patchlevel \EventSourcing \Subscription \Engine \DefaultSubscriptionEngine ;
99107use Patchlevel \EventSourcing \Subscription \Engine \GapResolverStoreMessageLoader ;
@@ -188,6 +196,7 @@ public function load(array $configs, ContainerBuilder $container): void
188196 $ this ->configureMigration ($ config , $ container );
189197 $ this ->configureValueResolver ($ container );
190198 $ this ->configureStoreMigration ($ config , $ container );
199+ $ this ->configureDCB ($ config , $ container );
191200 }
192201
193202 /** @param Config $config */
@@ -230,6 +239,9 @@ private function configureSerializer(array $config, ContainerBuilder $container)
230239 ]);
231240
232241 $ container ->setAlias (HeadersSerializer::class, DefaultHeadersSerializer::class);
242+
243+ $ container ->register (AttributeEventTagExtractor::class);
244+ $ container ->setAlias (EventTagExtractor::class, AttributeEventTagExtractor::class);
233245 }
234246
235247 /** @param Config $config */
@@ -627,6 +639,10 @@ private function configureMessageDecorator(ContainerBuilder $container): void
627639 ->setArguments ([new Reference (EventMetadataFactory::class)])
628640 ->addTag ('event_sourcing.message_decorator ' );
629641
642+ $ container ->register (EventTagDecorator::class)
643+ ->setArguments ([new Reference (EventTagExtractor::class)])
644+ ->addTag ('event_sourcing.message_decorator ' );
645+
630646 $ container ->registerForAutoconfiguration (MessageDecorator::class)
631647 ->addTag ('event_sourcing.message_decorator ' );
632648
@@ -721,7 +737,7 @@ private function configureStore(array $config, ContainerBuilder $container): voi
721737 $ container ->setAlias (Store::class, StreamDoctrineDbalStore::class);
722738
723739 if ($ config ['store ' ]['read_only ' ]) {
724- $ container ->register (StreamReadOnlyStore ::class)
740+ $ container ->register (ReadOnlyStore ::class)
725741 ->setDecoratedService (Store::class)
726742 ->setArguments ([
727743 new Reference ('.inner ' ),
@@ -731,6 +747,27 @@ private function configureStore(array $config, ContainerBuilder $container): voi
731747 return ;
732748 }
733749
750+ if ($ config ['store ' ]['type ' ] === 'dbal_taggable ' ) {
751+ $ container ->register (TaggableDoctrineDbalStore::class)
752+ ->setArguments ([
753+ new Reference ('event_sourcing.dbal_connection ' ),
754+ new Reference (EventSerializer::class),
755+ new Reference (EventRegistry::class),
756+ new Reference (HeadersSerializer::class),
757+ new Reference ('event_sourcing.clock ' ),
758+ $ config ['store ' ]['options ' ],
759+ ])
760+ ->addTag ('event_sourcing.doctrine_schema_configurator ' );
761+
762+ $ container ->setAlias (Store::class, TaggableDoctrineDbalStore::class);
763+
764+ if ($ config ['store ' ]['read_only ' ]) {
765+ throw new InvalidArgumentException ('Taggable store does not support read only ' );
766+ }
767+
768+ return ;
769+ }
770+
734771 throw new InvalidArgumentException (sprintf ('Unknown store type "%s" ' , $ config ['store ' ]['type ' ]));
735772 }
736773
@@ -784,6 +821,20 @@ private function configureStoreMigration(array $config, ContainerBuilder $contai
784821 return ;
785822 }
786823
824+ if ($ config ['store ' ]['migrate_to_new_store ' ]['type ' ] === 'dbal_taggable ' ) {
825+ $ container ->register ($ id , TaggableDoctrineDbalStore::class)
826+ ->setArguments ([
827+ new Reference ('event_sourcing.dbal_connection ' ),
828+ new Reference (EventSerializer::class),
829+ new Reference (HeadersSerializer::class),
830+ new Reference ('event_sourcing.clock ' ),
831+ $ config ['store ' ]['migrate_to_new_store ' ]['options ' ],
832+ ])
833+ ->addTag ('event_sourcing.doctrine_schema_configurator ' );
834+
835+ return ;
836+ }
837+
787838 throw new InvalidArgumentException (sprintf ('Unknown store type "%s" ' , $ config ['store ' ]['type ' ]));
788839 }
789840
@@ -1135,6 +1186,31 @@ private function configureCryptography(array $config, ContainerBuilder $containe
11351186 $ container ->setAlias (PayloadCryptographer::class, PersonalDataPayloadCryptographer::class);
11361187 }
11371188
1189+ /** @param Config $config */
1190+ private function configureDCB (array $ config , ContainerBuilder $ container ): void
1191+ {
1192+ if (!$ config ['dcb ' ]['enabled ' ]) {
1193+ return ;
1194+ }
1195+
1196+ if ($ config ['store ' ]['type ' ] !== 'dbal_taggable ' ) {
1197+ throw new InvalidArgumentException (
1198+ 'DCB requires a taggable store, please use "dbal_taggable" as store type. ' ,
1199+ );
1200+ }
1201+
1202+ $ container ->register (StoreDecisionModelBuilder::class)
1203+ ->setArguments ([new Reference (TaggableDoctrineDbalStore::class)]);
1204+ $ container ->setAlias (DecisionModelBuilder::class, StoreDecisionModelBuilder::class);
1205+
1206+ $ container ->register (StoreEventAppender::class)
1207+ ->setArguments ([
1208+ new Reference (TaggableDoctrineDbalStore::class),
1209+ new Reference (EventTagExtractor::class),
1210+ ]);
1211+ $ container ->setAlias (EventAppender::class, StoreEventAppender::class);
1212+ }
1213+
11381214 private function configureValueResolver (ContainerBuilder $ container ): void
11391215 {
11401216 $ container ->register (IdentifierValueResolver::class)
0 commit comments