Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"patchlevel/event-sourcing": "4.0.x-dev",
"patchlevel/hydrator": "^2.0.2",
"symfony/cache": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/config": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/console": "^6.4.1 || ^7.0.1 || ^8.0.0",
"symfony/dependency-injection": "^6.4.1 || ^7.0.1 || ^8.0.0",
"symfony/event-dispatcher": "^6.4.1 || ^7.0.1 || ^8.0.0",
"symfony/finder": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/http-kernel": "^6.4.1 || ^7.0.1 || ^8.0.0",
"symfony/messenger": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/cache": "^7.3.0 || ^8.0.0",
"symfony/config": "^7.3.0 || ^8.0.0",
"symfony/console": "^7.3.0 || ^8.0.0",
"symfony/dependency-injection": "^7.3.0 || ^8.0.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we could drop 6.4 for all components then, as framework users mostly update all components and not only one.

"symfony/event-dispatcher": "^7.3.0 || ^8.0.0",
"symfony/finder": "^7.3.0 || ^8.0.0",
"symfony/http-kernel": "^7.3.0 || ^8.0.0",
"symfony/messenger": "^7.3.0 || ^8.0.0",
"symfony/service-contracts": "^2.5 || ^3.0"
},
"require-dev": {
Expand All @@ -42,10 +42,10 @@
"phpstan/phpstan-symfony": "^2.0.8",
"phpunit/phpunit": "^11.5.45",
"roave/security-advisories": "dev-master",
"symfony/clock": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/uid": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/var-dumper": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/web-profiler-bundle": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/clock": "^7.3.0 || ^8.0.0",
"symfony/uid": "^7.3.0 || ^8.0.0",
"symfony/var-dumper": "^7.3.0 || ^8.0.0",
"symfony/web-profiler-bundle": "^7.3.0 || ^8.0.0",
"wnx/commonmark-markdown-renderer": "^1.4"
},
"suggest": {
Expand All @@ -55,7 +55,7 @@
},
"conflict": {
"doctrine/doctrine-bundle": "<2.8",
"symfony/event-dispatcher": "6.4.36 || 7.4.8 || 8.0.8"
"symfony/event-dispatcher": "7.4.8 || 8.0.8"
},
"config": {
"preferred-install": {
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 18 additions & 57 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,33 @@ This documentation is limited to bundle integration and configuration.
We provide a [default configuration](./installation.md#configuration-file) that should work for most projects.
:::

## Aggregate
## Aggregates, Events and Headers

A path must be specified for Event Sourcing to know where to look for your aggregates.
If you want you can use glob patterns to specify multiple paths.
Aggregates, events and custom headers are discovered via Symfony's service autoconfiguration.
Every class marked with the `#[Aggregate]`, `#[Event]` or `#[Header]` attribute that is covered
by a service resource with `autoconfigure` enabled is registered automatically.
These classes are not registered as services, they are only collected and then excluded from the container.

```yaml
patchlevel_event_sourcing:
aggregates: '%kernel.project_dir%/src/*/Domain'
```
Or use an array to specify multiple paths.
With the default Symfony configuration in `config/services.yaml` this works out of the box:

```yaml
patchlevel_event_sourcing:
aggregates:
- '%kernel.project_dir%/src/Hotel/Domain'
- '%kernel.project_dir%/src/Room/Domain'
```
:::note
The library will automatically register all classes marked with the `#[Aggregate]` attribute in the specified paths.
:::
services:
_defaults:
autowire: true
autoconfigure: true

:::tip
If you want to learn more about aggregates, read the [library documentation](https://event-sourcing.patchlevel.io/latest/aggregate/).
:::

## Events

A path must be specified for Event Sourcing to know where to look for your events.
If you want you can use glob patterns to specify multiple paths.

```yaml
patchlevel_event_sourcing:
events: '%kernel.project_dir%/src/*/Domain/Event'
App\:
resource: '../src/'
```
Or use an array to specify multiple paths.

```yaml
patchlevel_event_sourcing:
events:
- '%kernel.project_dir%/src/Hotel/Domain/Event'
- '%kernel.project_dir%/src/Room/Domain/Event'
```
:::tip
If you want to learn more about events, read the [library documentation](https://event-sourcing.patchlevel.io/latest/events/).
:::note
Make sure the directories containing your aggregates, events and headers are not listed in the `exclude` option.
:::

## Custom Headers

If you want to implement custom headers for your application, you must specify the
paths to look for those headers.
If you want you can use glob patterns to specify multiple paths.

```yaml
patchlevel_event_sourcing:
headers: '%kernel.project_dir%/src/*/Domain/Header'
```
Or use an array to specify multiple paths.

```yaml
patchlevel_event_sourcing:
headers:
- '%kernel.project_dir%/src/Hotel/Domain/Header'
- '%kernel.project_dir%/src/Room/Domain/Header'
```
:::tip
If you want to learn more about custom headers, read the [library documentation](https://event-sourcing.patchlevel.io/latest/message/#custom-headers).
If you want to learn more about [aggregates](https://event-sourcing.patchlevel.io/latest/aggregate/),
[events](https://event-sourcing.patchlevel.io/latest/events/)
or [custom headers](https://event-sourcing.patchlevel.io/latest/message/#custom-headers),
read the library documentation.
:::

## Connection
Expand Down
2 changes: 0 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ Now you have to add following recommended configuration file here `config/packag

```yaml
patchlevel_event_sourcing:
aggregates: '%kernel.project_dir%/src'
events: '%kernel.project_dir%/src'
connection:
url: '%env(EVENTSTORE_URL)%'
provide_dedicated_connection: true
Expand Down
18 changes: 0 additions & 18 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ parameters:
count: 1
path: tests/Fixtures/SnapshotableProfile.php

-
message: '#^Call to an undefined method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:getAutoconfiguredAttributes\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/Unit/PatchlevelEventSourcingBundleTest.php

-
message: '#^Cannot access offset ''Patchlevel\\\\EventSourcing\\\\Attribute\\\\Aggregate''\|''Patchlevel\\\\EventSourcing\\\\Attribute\\\\Event'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: tests/Unit/PatchlevelEventSourcingBundleTest.php

-
message: '#^Cannot access offset ''bus'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
Expand All @@ -83,9 +71,3 @@ parameters:
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: tests/Unit/PatchlevelEventSourcingBundleTest.php

-
message: '#^Trying to invoke mixed but it''s not a callable\.$#'
identifier: callable.nonCallable
count: 1
path: tests/Unit/PatchlevelEventSourcingBundleTest.php
7 changes: 3 additions & 4 deletions src/DependencyInjection/CommandHandlerCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Patchlevel\EventSourcing\CommandBus\Handler\CreateAggregateHandler;
use Patchlevel\EventSourcing\CommandBus\Handler\UpdateAggregateHandler;
use Patchlevel\EventSourcing\CommandBus\HandlerFinder;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry;
use Patchlevel\EventSourcing\Repository\RepositoryManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -30,14 +29,14 @@
$container->getParameter('patchlevel_event_sourcing.aggregate_handlers.bus'),
);

/** @var AggregateRootRegistry $aggregateRootRegistry */
$aggregateRootRegistry = $container->get(AggregateRootRegistry::class);
/** @var array<string, class-string> $aggregates */
$aggregates = $container->getParameter('event_sourcing.aggregates');

foreach ($aggregateRootRegistry->aggregateClasses() as $aggregateName => $aggregateClass) {
foreach ($aggregates as $aggregateName => $aggregateClass) {
$parameterResolverId = sprintf('.event_sourcing.handler_parameter_resolver.%s', $aggregateName);

foreach (HandlerFinder::findInClass($aggregateClass) as $aggregateHandler) {
$handlerId = strtolower(sprintf('event_sourcing.handler.%s.%s', $aggregateName, $aggregateHandler->method));

Check warning on line 39 in src/DependencyInjection/CommandHandlerCompilerPass.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "UnwrapStrToLower": @@ @@ $parameterResolverId = sprintf('.event_sourcing.handler_parameter_resolver.%s', $aggregateName); foreach (HandlerFinder::findInClass($aggregateClass) as $aggregateHandler) { - $handlerId = strtolower(sprintf('event_sourcing.handler.%s.%s', $aggregateName, $aggregateHandler->method)); + $handlerId = sprintf('event_sourcing.handler.%s.%s', $aggregateName, $aggregateHandler->method); $handlerClass = $aggregateHandler->static ? CreateAggregateHandler::class : UpdateAggregateHandler::class; $container->register($handlerId, $handlerClass)
$handlerClass = $aggregateHandler->static ? CreateAggregateHandler::class : UpdateAggregateHandler::class;

$container->register($handlerId, $handlerClass)
Expand Down
21 changes: 0 additions & 21 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@
* translators: list<string>
* }
* },
* aggregates: list<string>,
* events: list<string>,
* headers: list<string>,
* snapshot_stores: array<string, array{type: string, service: string}>,
* migration: array{path: string, namespace: string},
* clock: array{freeze: ?string, service: ?string},
Expand Down Expand Up @@ -156,24 +153,6 @@
->end()
->end()

->arrayNode('events')
->beforeNormalization()->castToArray()->end()
->defaultValue([])
->scalarPrototype()->end()
->end()

->arrayNode('aggregates')
->beforeNormalization()->castToArray()->end()
->defaultValue([])
->scalarPrototype()->end()
->end()

->arrayNode('headers')
->beforeNormalization()->castToArray()->end()
->defaultValue([])
->scalarPrototype()->end()
->end()

->arrayNode('clock')
->addDefaultsIfNotSet()
->children()
Expand Down Expand Up @@ -205,7 +184,7 @@
->children()
->arrayNode('store')
->addDefaultsIfNotSet()
->children()

Check warning on line 187 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ ->addDefaultsIfNotSet() ->children() ->enumNode('type') - ->values(['dbal', 'in_memory', 'static_in_memory', 'custom']) + ->values(['in_memory', 'static_in_memory', 'custom']) ->defaultValue('dbal') ->end() ->scalarNode('service')->defaultNull()->end()
->enumNode('type')
->values(['dbal', 'in_memory', 'static_in_memory', 'custom'])
->defaultValue('dbal')
Expand All @@ -227,13 +206,13 @@
->enumNode('type')->values(['clock_based', 'no_retry', 'custom'])->end()
->scalarNode('service')->end()
->arrayNode('options')->variablePrototype()->end()->end()
->end()

Check warning on line 209 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ ->end() ->end() ->defaultValue([ - 'default' => [ - 'type' => 'clock_based', - 'options' => [ - 'base_delay' => 5, - 'delay_factor' => 2, - 'max_attempts' => 5, - ], - ], 'no_retry' => [ 'type' => 'no_retry', ],
->end()
->defaultValue([
'default' => [

Check warning on line 212 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ 'default' => [ 'type' => 'clock_based', 'options' => [ - 'base_delay' => 5, 'delay_factor' => 2, 'max_attempts' => 5, ],
'type' => 'clock_based',

Check warning on line 213 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "IncrementInteger": @@ @@ 'default' => [ 'type' => 'clock_based', 'options' => [ - 'base_delay' => 5, + 'base_delay' => 6, 'delay_factor' => 2, 'max_attempts' => 5, ],

Check warning on line 213 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "DecrementInteger": @@ @@ 'default' => [ 'type' => 'clock_based', 'options' => [ - 'base_delay' => 5, + 'base_delay' => 4, 'delay_factor' => 2, 'max_attempts' => 5, ],
'options' => [

Check warning on line 214 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "IncrementInteger": @@ @@ 'type' => 'clock_based', 'options' => [ 'base_delay' => 5, - 'delay_factor' => 2, + 'delay_factor' => 3, 'max_attempts' => 5, ], ],

Check warning on line 214 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "DecrementInteger": @@ @@ 'type' => 'clock_based', 'options' => [ 'base_delay' => 5, - 'delay_factor' => 2, + 'delay_factor' => 1, 'max_attempts' => 5, ], ],
'base_delay' => 5,

Check warning on line 215 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "IncrementInteger": @@ @@ 'options' => [ 'base_delay' => 5, 'delay_factor' => 2, - 'max_attempts' => 5, + 'max_attempts' => 6, ], ], 'no_retry' => [

Check warning on line 215 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.5, ubuntu-latest)

Escaped Mutant for Mutator "DecrementInteger": @@ @@ 'options' => [ 'base_delay' => 5, 'delay_factor' => 2, - 'max_attempts' => 5, + 'max_attempts' => 4, ], ], 'no_retry' => [
'delay_factor' => 2,
'max_attempts' => 5,
],
Expand Down
7 changes: 3 additions & 4 deletions src/DependencyInjection/HandlerServiceLocatorCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Patchlevel\EventSourcing\Attribute\Inject;
use Patchlevel\EventSourcing\CommandBus\Handler\ServiceNotResolvable;
use Patchlevel\EventSourcing\CommandBus\HandlerFinder;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry;
use Patchlevel\EventSourcingBundle\CommandBus\SymfonyParameterResolver;
use Psr\Container\ContainerInterface;
use ReflectionAttribute;
Expand All @@ -32,10 +31,10 @@ public function process(ContainerBuilder $container): void
return;
}

/** @var AggregateRootRegistry $aggregateRootRegistry */
$aggregateRootRegistry = $container->get(AggregateRootRegistry::class);
/** @var array<string, class-string> $aggregates */
$aggregates = $container->getParameter('event_sourcing.aggregates');

foreach ($aggregateRootRegistry->aggregateClasses() as $aggregateName => $aggregateClass) {
foreach ($aggregates as $aggregateName => $aggregateClass) {
$parameterResolverId = sprintf('.event_sourcing.handler_parameter_resolver.%s', $aggregateName);
$services = [];

Expand Down
Loading
Loading