Skip to content

Commit b67b06a

Browse files
committed
Merge remote-tracking branch 'origin/4.0.x' into 3.13.x-merge-up-into-4.0.x_9LnNIwEP
2 parents d1a8538 + f5e8415 commit b67b06a

14 files changed

Lines changed: 145 additions & 99 deletions

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": "4.0.x-dev",
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: 16 additions & 14 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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
* },
7979
* clock: array{freeze: ?string, service: ?string},
8080
* aggregate_handlers: array{enabled: bool, bus: string|null},
81+
* dcb: array{enabled: bool},
8182
* }
8283
*/
8384
final class Configuration implements ConfigurationInterface
@@ -102,8 +103,8 @@ public function getConfigTreeBuilder(): TreeBuilder
102103
->addDefaultsIfNotSet()
103104
->children()
104105
->enumNode('type')
105-
->values(['dbal_aggregate', 'dbal_stream', 'in_memory', 'custom'])
106-
->defaultValue('dbal_aggregate')
106+
->values(['dbal_stream', 'dbal_taggable', 'in_memory', 'custom'])
107+
->defaultValue('dbal_stream')
107108
->end()
108109
->scalarNode('service')->defaultNull()->end()
109110
->booleanNode('merge_orm_schema')->defaultFalse()->end()
@@ -114,7 +115,7 @@ public function getConfigTreeBuilder(): TreeBuilder
114115
->addDefaultsIfNotSet()
115116
->children()
116117
->enumNode('type')
117-
->values(['dbal_aggregate', 'dbal_stream', 'in_memory', 'custom'])
118+
->values(['dbal_stream', 'dbal_taggable', 'in_memory', 'custom'])
118119
->end()
119120
->scalarNode('service')->defaultNull()->end()
120121
->arrayNode('options')->variablePrototype()->end()->end()
@@ -331,6 +332,10 @@ public function getConfigTreeBuilder(): TreeBuilder
331332
->end()
332333
->end()
333334

335+
->arrayNode('dcb')
336+
->canBeEnabled()
337+
->end()
338+
334339
->arrayNode('aggregate_handlers')
335340
->canBeEnabled()
336341
->addDefaultsIfNotSet()

src/DependencyInjection/PatchlevelEventSourcingExtension.php

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
use Patchlevel\EventSourcing\Console\Command\WatchCommand;
4646
use Patchlevel\EventSourcing\Console\DoctrineHelper;
4747
use 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;
4852
use Patchlevel\EventSourcing\EventBus\AttributeListenerProvider;
4953
use Patchlevel\EventSourcing\EventBus\Consumer;
5054
use Patchlevel\EventSourcing\EventBus\DefaultConsumer;
@@ -70,6 +74,7 @@
7074
use Patchlevel\EventSourcing\QueryBus\QueryBus;
7175
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
7276
use Patchlevel\EventSourcing\Repository\MessageDecorator\ChainMessageDecorator;
77+
use Patchlevel\EventSourcing\Repository\MessageDecorator\EventTagDecorator;
7378
use Patchlevel\EventSourcing\Repository\MessageDecorator\MessageDecorator;
7479
use Patchlevel\EventSourcing\Repository\MessageDecorator\SplitStreamDecorator;
7580
use Patchlevel\EventSourcing\Repository\RepositoryManager;
@@ -80,22 +85,23 @@
8085
use Patchlevel\EventSourcing\Schema\DoctrineSchemaListener;
8186
use Patchlevel\EventSourcing\Schema\DoctrineSchemaProvider;
8287
use Patchlevel\EventSourcing\Schema\SchemaDirector;
88+
use Patchlevel\EventSourcing\Serializer\AttributeEventTagExtractor;
8389
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
8490
use Patchlevel\EventSourcing\Serializer\Encoder\Encoder;
8591
use Patchlevel\EventSourcing\Serializer\Encoder\JsonEncoder;
8692
use Patchlevel\EventSourcing\Serializer\EventSerializer;
93+
use Patchlevel\EventSourcing\Serializer\EventTagExtractor;
8794
use Patchlevel\EventSourcing\Serializer\Upcast\Upcaster;
8895
use Patchlevel\EventSourcing\Serializer\Upcast\UpcasterChain;
8996
use Patchlevel\EventSourcing\Snapshot\Adapter\Psr16SnapshotAdapter;
9097
use Patchlevel\EventSourcing\Snapshot\Adapter\Psr6SnapshotAdapter;
9198
use Patchlevel\EventSourcing\Snapshot\DefaultSnapshotStore;
9299
use Patchlevel\EventSourcing\Snapshot\SnapshotStore;
93-
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
94100
use Patchlevel\EventSourcing\Store\InMemoryStore;
95101
use Patchlevel\EventSourcing\Store\ReadOnlyStore;
96102
use Patchlevel\EventSourcing\Store\Store;
97103
use Patchlevel\EventSourcing\Store\StreamDoctrineDbalStore;
98-
use Patchlevel\EventSourcing\Store\StreamReadOnlyStore;
104+
use Patchlevel\EventSourcing\Store\TaggableDoctrineDbalStore;
99105
use Patchlevel\EventSourcing\Subscription\Engine\CatchUpSubscriptionEngine;
100106
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
101107
use Patchlevel\EventSourcing\Subscription\Engine\GapResolverStoreMessageLoader;
@@ -128,7 +134,7 @@
128134
use Patchlevel\EventSourcingBundle\RequestListener\SubscriptionRebuildAfterFileChangeListener;
129135
use Patchlevel\EventSourcingBundle\Subscription\ResetServicesListener;
130136
use Patchlevel\EventSourcingBundle\Subscription\StaticInMemorySubscriptionStoreFactory;
131-
use Patchlevel\EventSourcingBundle\ValueResolver\AggregateRootIdValueResolver;
137+
use Patchlevel\EventSourcingBundle\ValueResolver\IdentifierValueResolver;
132138
use Patchlevel\Hydrator\Cryptography\Cipher\Cipher;
133139
use Patchlevel\Hydrator\Cryptography\Cipher\CipherKeyFactory;
134140
use 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

src/ValueResolver/AggregateRootIdValueResolver.php renamed to src/ValueResolver/IdentifierValueResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
namespace Patchlevel\EventSourcingBundle\ValueResolver;
66

7-
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
7+
use Patchlevel\EventSourcing\Identifier\Identifier;
88
use Symfony\Component\HttpFoundation\Request;
99
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
1010
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
1111

1212
use function is_a;
1313
use function is_string;
1414

15-
final class AggregateRootIdValueResolver implements ValueResolverInterface
15+
final class IdentifierValueResolver implements ValueResolverInterface
1616
{
17-
/** @return iterable<AggregateRootId> */
17+
/** @return iterable<Identifier> */
1818
public function resolve(Request $request, ArgumentMetadata $argument): iterable
1919
{
2020
$argumentType = $argument->getType();
2121

22-
if ($argumentType === null || !is_a($argumentType, AggregateRootId::class, true)) {
22+
if ($argumentType === null || !is_a($argumentType, Identifier::class, true)) {
2323
return [];
2424
}
2525

tests/Fixtures/CreateProfile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Patchlevel\EventSourcingBundle\Tests\Fixtures;
44

5-
use Patchlevel\EventSourcing\Aggregate\CustomId;
5+
use Patchlevel\EventSourcing\Identifier\CustomId;
66

77
class CreateProfile
88
{

tests/Fixtures/Profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Patchlevel\EventSourcingBundle\Tests\Fixtures;
44

55
use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot;
6-
use Patchlevel\EventSourcing\Aggregate\CustomId;
6+
use Patchlevel\EventSourcing\Identifier\CustomId;
77
use Patchlevel\EventSourcing\Attribute\Aggregate;
88
use Patchlevel\EventSourcing\Attribute\Apply;
99
use Patchlevel\EventSourcing\Attribute\Handle;

tests/Fixtures/ProfileCreated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Patchlevel\EventSourcingBundle\Tests\Fixtures;
44

5-
use Patchlevel\EventSourcing\Aggregate\CustomId;
5+
use Patchlevel\EventSourcing\Identifier\CustomId;
66
use Patchlevel\EventSourcing\Attribute\Event;
77
use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;
88

0 commit comments

Comments
 (0)