Skip to content

Commit 87db491

Browse files
authored
Merge pull request #284 from patchlevel/add-table-options-and-clock
Add table options for subscription store, update docs & default config
2 parents 11a01eb + 5298f5f commit 87db491

14 files changed

Lines changed: 132 additions & 20 deletions

docs/pages/configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ patchlevel_event_sourcing:
340340
store:
341341
type: 'custom' # default is 'dbal'
342342
service: 'my_subscription_store'
343+
options:
344+
table_name: 'my_subscription_store'
343345
```
344346
!!! tip
345347

@@ -670,7 +672,7 @@ For this you need to enable the crypto shredding.
670672
```yaml
671673
patchlevel_event_sourcing:
672674
cryptography:
673-
use_encrypted_field_name: true,
675+
use_encrypted_field_name: true
674676
```
675677

676678
!!! tip

docs/pages/installation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ patchlevel_event_sourcing:
3737
connection:
3838
url: '%env(EVENTSTORE_URL)%'
3939
provide_dedicated_connection: true
40+
store:
41+
type: dbal_stream
42+
# if you are using doctrine bundle you should enable this
43+
#merge_orm_schema: true
44+
command_bus:
45+
service: messenger.default_bus
46+
query_bus:
47+
service: messenger.default_bus
48+
subscription:
49+
gap_detection: ~
50+
51+
# enable this if you want to use sensitive data encryption
52+
#cryptography: ~
53+
# use_encrypted_field_name: true
4054

4155
when@dev:
4256
patchlevel_event_sourcing:
@@ -50,6 +64,8 @@ when@dev:
5064
when@test:
5165
patchlevel_event_sourcing:
5266
subscription:
67+
store:
68+
type: 'static_in_memory'
5369
catch_up: true
5470
throw_on_error: true
5571
run_after_aggregate_save: true

docs/pages/usage.md

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

33
Here you will find some examples of how to use the bundle.
4-
But we provide only examples for specific symfo
4+
But we provide only examples for specific symfony features.
55

66
!!! info
77

phpstan-baseline.neon

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,67 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: '#^Parameter \#2 \$id of static method Patchlevel\\EventSourcingBundle\\DependencyInjection\\ServiceAliasResolver\:\:resolve\(\) expects string, array\|bool\|float\|int\|string\|null given\.$#'
5+
identifier: argument.type
6+
count: 1
7+
path: src/DependencyInjection/CommandHandlerCompilerPass.php
8+
39
-
410
message: '#^Parameter \#1 \$classString of static method Patchlevel\\EventSourcing\\QueryBus\\HandlerFinder\:\:findInClass\(\) expects class\-string, string given\.$#'
511
identifier: argument.type
612
count: 1
713
path: src/DependencyInjection/QueryHandlerCompilerPass.php
14+
15+
-
16+
message: '#^Parameter \#2 \$id of static method Patchlevel\\EventSourcingBundle\\DependencyInjection\\ServiceAliasResolver\:\:resolve\(\) expects string, array\|bool\|float\|int\|string\|null given\.$#'
17+
identifier: argument.type
18+
count: 1
19+
path: src/DependencyInjection/QueryHandlerCompilerPass.php
20+
21+
-
22+
message: '#^Property Patchlevel\\EventSourcingBundle\\Tests\\Fixtures\\Profile\:\:\$id is never read, only written\.$#'
23+
identifier: property.onlyWritten
24+
count: 1
25+
path: tests/Fixtures/Profile.php
26+
27+
-
28+
message: '#^Property Patchlevel\\EventSourcingBundle\\Tests\\Fixtures\\SnapshotableProfile\:\:\$id is unused\.$#'
29+
identifier: property.unused
30+
count: 1
31+
path: tests/Fixtures/SnapshotableProfile.php
32+
33+
-
34+
message: '#^Call to an undefined method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:getAutoconfiguredAttributes\(\)\.$#'
35+
identifier: method.notFound
36+
count: 1
37+
path: tests/Unit/PatchlevelEventSourcingBundleTest.php
38+
39+
-
40+
message: '#^Cannot access offset ''Patchlevel\\\\EventSourcing\\\\Attribute\\\\Aggregate''\|''Patchlevel\\\\EventSourcing\\\\Attribute\\\\Event'' on mixed\.$#'
41+
identifier: offsetAccess.nonOffsetAccessible
42+
count: 1
43+
path: tests/Unit/PatchlevelEventSourcingBundleTest.php
44+
45+
-
46+
message: '#^Cannot access offset ''bus'' on mixed\.$#'
47+
identifier: offsetAccess.nonOffsetAccessible
48+
count: 3
49+
path: tests/Unit/PatchlevelEventSourcingBundleTest.php
50+
51+
-
52+
message: '#^Cannot access offset ''handles'' on mixed\.$#'
53+
identifier: offsetAccess.nonOffsetAccessible
54+
count: 3
55+
path: tests/Unit/PatchlevelEventSourcingBundleTest.php
56+
57+
-
58+
message: '#^Cannot access offset ''method'' on mixed\.$#'
59+
identifier: offsetAccess.nonOffsetAccessible
60+
count: 2
61+
path: tests/Unit/PatchlevelEventSourcingBundleTest.php
62+
63+
-
64+
message: '#^Trying to invoke mixed but it''s not a callable\.$#'
65+
identifier: callable.nonCallable
66+
count: 1
67+
path: tests/Unit/PatchlevelEventSourcingBundleTest.php

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ parameters:
66
level: max
77
paths:
88
- src
9+
- tests

src/DependencyInjection/CommandHandlerCompilerPass.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function process(ContainerBuilder $container): void
2525
return;
2626
}
2727

28-
$bus = $container->getParameter('patchlevel_event_sourcing.aggregate_handlers.bus');
28+
$bus = ServiceAliasResolver::resolve(
29+
$container,
30+
$container->getParameter('patchlevel_event_sourcing.aggregate_handlers.bus'),
31+
);
2932

3033
/** @var AggregateRootRegistry $aggregateRootRegistry */
3134
$aggregateRootRegistry = $container->get(AggregateRootRegistry::class);

src/DependencyInjection/Configuration.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
* },
2323
* query_bus: array{enabled: bool, service: string},
2424
* subscription: array{
25-
* store: array{type: string, service: string|null},
25+
* store: array{
26+
* type: string,
27+
* service: string|null,
28+
* options: array{table_name: string}
29+
* },
2630
* retry_strategy?: array{base_delay: int, delay_factor: int, max_attempts: int},
2731
* retry_strategies: array<string, array{type: string, service: string, options: array<string, mixed>}>,
2832
* default_retry_strategy: string,
@@ -197,6 +201,12 @@ public function getConfigTreeBuilder(): TreeBuilder
197201
->defaultValue('dbal')
198202
->end()
199203
->scalarNode('service')->defaultNull()->end()
204+
->arrayNode('options')
205+
->addDefaultsIfNotSet()
206+
->children()
207+
->scalarNode('table_name')->defaultValue('subscriptions')->end()
208+
->end()
209+
->end()
200210
->end()
201211
->end()
202212

src/DependencyInjection/PatchlevelEventSourcingExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ static function (ChildDefinition $definition): void {
488488
$container->register(DoctrineSubscriptionStore::class)
489489
->setArguments([
490490
new Reference('event_sourcing.dbal_connection'),
491+
new Reference('event_sourcing.clock'),
492+
$config['subscription']['store']['options']['table_name'],
491493
])
492494
->addTag('event_sourcing.doctrine_schema_configurator');
493495

src/DependencyInjection/QueryHandlerCompilerPass.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public function process(ContainerBuilder $container): void
1919
return;
2020
}
2121

22-
$bus = $container->getParameter('patchlevel_event_sourcing.query_handlers.bus');
22+
$bus = ServiceAliasResolver::resolve(
23+
$container,
24+
$container->getParameter('patchlevel_event_sourcing.query_handlers.bus'),
25+
);
2326
$subscribers = $container->findTaggedServiceIds('event_sourcing.subscriber');
2427

2528
foreach (array_keys($subscribers) as $subscriberServiceName) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcingBundle\DependencyInjection;
6+
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
9+
/** @interal */
10+
final readonly class ServiceAliasResolver
11+
{
12+
public static function resolve(ContainerBuilder $container, string $id): string
13+
{
14+
if ($container->hasAlias($id)) {
15+
return self::resolve(
16+
$container,
17+
(string)$container->getAlias($id),
18+
);
19+
}
20+
21+
return $id;
22+
}
23+
}

0 commit comments

Comments
 (0)