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 ;
93- use Patchlevel \EventSourcing \Store \DoctrineDbalStore ;
94100use Patchlevel \EventSourcing \Store \InMemoryStore ;
95101use Patchlevel \EventSourcing \Store \ReadOnlyStore ;
96102use Patchlevel \EventSourcing \Store \Store ;
97103use Patchlevel \EventSourcing \Store \StreamDoctrineDbalStore ;
98- use Patchlevel \EventSourcing \Store \StreamReadOnlyStore ;
104+ use Patchlevel \EventSourcing \Store \TaggableDoctrineDbalStore ;
99105use Patchlevel \EventSourcing \Subscription \Engine \CatchUpSubscriptionEngine ;
100106use Patchlevel \EventSourcing \Subscription \Engine \DefaultSubscriptionEngine ;
101107use Patchlevel \EventSourcing \Subscription \Engine \GapResolverStoreMessageLoader ;
128134use Patchlevel \EventSourcingBundle \RequestListener \SubscriptionRebuildAfterFileChangeListener ;
129135use Patchlevel \EventSourcingBundle \Subscription \ResetServicesListener ;
130136use Patchlevel \EventSourcingBundle \Subscription \StaticInMemorySubscriptionStoreFactory ;
131- use Patchlevel \EventSourcingBundle \ValueResolver \AggregateRootIdValueResolver ;
137+ use Patchlevel \EventSourcingBundle \ValueResolver \IdentifierValueResolver ;
132138use Patchlevel \Hydrator \Cryptography \Cipher \Cipher ;
133139use Patchlevel \Hydrator \Cryptography \Cipher \CipherKeyFactory ;
134140use Patchlevel \Hydrator \Cryptography \Cipher \OpensslCipher ;
@@ -190,6 +196,7 @@ public function load(array $configs, ContainerBuilder $container): void
190196 $ this ->configureMigration ($ config , $ container );
191197 $ this ->configureValueResolver ($ container );
192198 $ this ->configureStoreMigration ($ config , $ container );
199+ $ this ->configureDCB ($ config , $ container );
193200 }
194201
195202 /** @param Config $config */
@@ -232,6 +239,9 @@ private function configureSerializer(array $config, ContainerBuilder $container)
232239 ]);
233240
234241 $ container ->setAlias (HeadersSerializer::class, DefaultHeadersSerializer::class);
242+
243+ $ container ->register (AttributeEventTagExtractor::class);
244+ $ container ->setAlias (EventTagExtractor::class, AttributeEventTagExtractor::class);
235245 }
236246
237247 /** @param Config $config */
@@ -629,6 +639,10 @@ private function configureMessageDecorator(ContainerBuilder $container): void
629639 ->setArguments ([new Reference (EventMetadataFactory::class)])
630640 ->addTag ('event_sourcing.message_decorator ' );
631641
642+ $ container ->register (EventTagDecorator::class)
643+ ->setArguments ([new Reference (EventTagExtractor::class)])
644+ ->addTag ('event_sourcing.message_decorator ' );
645+
632646 $ container ->registerForAutoconfiguration (MessageDecorator::class)
633647 ->addTag ('event_sourcing.message_decorator ' );
634648
@@ -714,17 +728,18 @@ private function configureStore(array $config, ContainerBuilder $container): voi
714728 return ;
715729 }
716730
717- if ($ config ['store ' ]['type ' ] === 'dbal_aggregate ' ) {
718- $ container ->register (DoctrineDbalStore ::class)
731+ if ($ config ['store ' ]['type ' ] === 'dbal_stream ' ) {
732+ $ container ->register (StreamDoctrineDbalStore ::class)
719733 ->setArguments ([
720734 new Reference ('event_sourcing.dbal_connection ' ),
721735 new Reference (EventSerializer::class),
722736 new Reference (HeadersSerializer::class),
737+ new Reference ('event_sourcing.clock ' ),
723738 $ config ['store ' ]['options ' ],
724739 ])
725740 ->addTag ('event_sourcing.doctrine_schema_configurator ' );
726741
727- $ container ->setAlias (Store::class, DoctrineDbalStore ::class);
742+ $ container ->setAlias (Store::class, StreamDoctrineDbalStore ::class);
728743
729744 if ($ config ['store ' ]['read_only ' ]) {
730745 $ container ->register (ReadOnlyStore::class)
@@ -737,25 +752,22 @@ private function configureStore(array $config, ContainerBuilder $container): voi
737752 return ;
738753 }
739754
740- if ($ config ['store ' ]['type ' ] === 'dbal_stream ' ) {
741- $ container ->register (StreamDoctrineDbalStore ::class)
755+ if ($ config ['store ' ]['type ' ] === 'dbal_taggable ' ) {
756+ $ container ->register (TaggableDoctrineDbalStore ::class)
742757 ->setArguments ([
743758 new Reference ('event_sourcing.dbal_connection ' ),
744759 new Reference (EventSerializer::class),
760+ new Reference (EventRegistry::class),
745761 new Reference (HeadersSerializer::class),
746762 new Reference ('event_sourcing.clock ' ),
747763 $ config ['store ' ]['options ' ],
748764 ])
749765 ->addTag ('event_sourcing.doctrine_schema_configurator ' );
750766
751- $ container ->setAlias (Store::class, StreamDoctrineDbalStore ::class);
767+ $ container ->setAlias (Store::class, TaggableDoctrineDbalStore ::class);
752768
753769 if ($ config ['store ' ]['read_only ' ]) {
754- $ container ->register (StreamReadOnlyStore::class)
755- ->setDecoratedService (Store::class)
756- ->setArguments ([
757- new Reference ('.inner ' ),
758- ]);
770+ throw new InvalidArgumentException ('Taggable store does not support read only ' );
759771 }
760772
761773 return ;
@@ -800,21 +812,22 @@ private function configureStoreMigration(array $config, ContainerBuilder $contai
800812 return ;
801813 }
802814
803- if ($ config ['store ' ]['migrate_to_new_store ' ]['type ' ] === 'dbal_aggregate ' ) {
804- $ container ->register ($ id , DoctrineDbalStore ::class)
815+ if ($ config ['store ' ]['migrate_to_new_store ' ]['type ' ] === 'dbal_stream ' ) {
816+ $ container ->register ($ id , StreamDoctrineDbalStore ::class)
805817 ->setArguments ([
806818 new Reference ('event_sourcing.dbal_connection ' ),
807819 new Reference (EventSerializer::class),
808820 new Reference (HeadersSerializer::class),
821+ new Reference ('event_sourcing.clock ' ),
809822 $ config ['store ' ]['migrate_to_new_store ' ]['options ' ],
810823 ])
811824 ->addTag ('event_sourcing.doctrine_schema_configurator ' );
812825
813826 return ;
814827 }
815828
816- if ($ config ['store ' ]['migrate_to_new_store ' ]['type ' ] === 'dbal_stream ' ) {
817- $ container ->register ($ id , StreamDoctrineDbalStore ::class)
829+ if ($ config ['store ' ]['migrate_to_new_store ' ]['type ' ] === 'dbal_taggable ' ) {
830+ $ container ->register ($ id , TaggableDoctrineDbalStore ::class)
818831 ->setArguments ([
819832 new Reference ('event_sourcing.dbal_connection ' ),
820833 new Reference (EventSerializer::class),
@@ -1178,9 +1191,34 @@ private function configureCryptography(array $config, ContainerBuilder $containe
11781191 $ container ->setAlias (PayloadCryptographer::class, PersonalDataPayloadCryptographer::class);
11791192 }
11801193
1194+ /** @param Config $config */
1195+ private function configureDCB (array $ config , ContainerBuilder $ container ): void
1196+ {
1197+ if (!$ config ['dcb ' ]['enabled ' ]) {
1198+ return ;
1199+ }
1200+
1201+ if ($ config ['store ' ]['type ' ] !== 'dbal_taggable ' ) {
1202+ throw new InvalidArgumentException (
1203+ 'DCB requires a taggable store, please use "dbal_taggable" as store type. ' ,
1204+ );
1205+ }
1206+
1207+ $ container ->register (StoreDecisionModelBuilder::class)
1208+ ->setArguments ([new Reference (TaggableDoctrineDbalStore::class)]);
1209+ $ container ->setAlias (DecisionModelBuilder::class, StoreDecisionModelBuilder::class);
1210+
1211+ $ container ->register (StoreEventAppender::class)
1212+ ->setArguments ([
1213+ new Reference (TaggableDoctrineDbalStore::class),
1214+ new Reference (EventTagExtractor::class),
1215+ ]);
1216+ $ container ->setAlias (EventAppender::class, StoreEventAppender::class);
1217+ }
1218+
11811219 private function configureValueResolver (ContainerBuilder $ container ): void
11821220 {
1183- $ container ->register (AggregateRootIdValueResolver ::class)
1221+ $ container ->register (IdentifierValueResolver ::class)
11841222 ->addTag ('controller.argument_value_resolver ' , ['priority ' => 200 ]);
11851223 }
11861224
0 commit comments