Skip to content

Commit

Permalink
Merge pull request #348 from patchlevel/2.1.x
Browse files Browse the repository at this point in the history
merge 2.1.x into 2.2.x
  • Loading branch information
DavidBadura authored Dec 27, 2022
2 parents 8201ba3 + 5c1bd79 commit 1201de1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ A lightweight but also all-inclusive event sourcing library with a focus on deve
* Everything is included in the package for event sourcing
* Based on [doctrine dbal](https://github.com/doctrine/dbal) and their ecosystem
* Developer experience oriented and fully typed
* [Snapshots](https://patchlevel.github.io/event-sourcing-docs/latest/snapshots/) system to quickly rebuild the aggregates
* [Snapshots](https://patchlevel.github.io/event-sourcing-docs/latest/snapshots/) and [Split-Stream](https://patchlevel.github.io/event-sourcing-docs/latest/split_stream/) system to quickly rebuild the aggregates
* [Pipeline](https://patchlevel.github.io/event-sourcing-docs/latest/pipeline/) to build new [projections](https://patchlevel.github.io/event-sourcing-docs/latest/projection/) or to migrate events
* [Projectionist](https://patchlevel.github.io/event-sourcing-docs/latest/projectionist/) for managed, versioned and asynchronous projections
* [Scheme management](https://patchlevel.github.io/event-sourcing-docs/latest/store/) and [doctrine migration](https://patchlevel.github.io/event-sourcing-docs/latest/migration/) support
* [Splitting the eventstream](https://patchlevel.github.io/event-sourcing-docs/latest/split_stream/)
* Dev [tools](https://patchlevel.github.io/event-sourcing-docs/latest/watch_server/) such as a realtime event watcher
* Built in [cli commands](https://patchlevel.github.io/event-sourcing-docs/latest/cli/) with [symfony](https://symfony.com/)

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ final class NameChanged

!!! note

You can find out more about event normalizer [here](./events.md#normalizer).
You can find out more about normalizer [here](./normalizer.md).

There are also cases where business rules have to be defined depending on the aggregate state.
Sometimes also from states, which were changed in the same method.
Expand Down
5 changes: 3 additions & 2 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ A lightweight but also all-inclusive event sourcing library with a focus on deve
* Everything is included in the package for event sourcing
* Based on [doctrine dbal](https://github.com/doctrine/dbal) and their ecosystem
* Developer experience oriented and fully typed
* [Snapshots](snapshots.md) system to quickly rebuild the aggregates
* [Snapshots](snapshots.md) and [Split-Stream](split_stream.md) system to quickly rebuild the aggregates
* [Pipeline](pipeline.md) to build new [projections](projection.md) or to migrate events
* [Scheme management](store.md) and [doctrine migration](store.md) support
* [Projectionist](projectionist.md) for managed, versioned and asynchronous projections
* [Scheme management](store.md) and [doctrine migration](migration.md) support
* Dev [tools](watch_server.md) such as a realtime event watcher
* Built in [cli commands](cli.md) with [symfony](https://symfony.com/)

Expand Down
91 changes: 69 additions & 22 deletions docs/pages/message_decorator.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,56 @@ There are usecases where you want to add some extra context to your events like
for your domain. With `MessageDecorator` we are providing a solution to add this metadata to your events. The metadata
will also be persisted in the database and can be retrieved later on.

## Create own decorator
## Built-in decorator

You can also use this feature to add your own metadata to your events. For this the have an extra methods on `Message`
to add data `withCustomHeader` and to read this data later on `customHeader`.
We offer a few decorators that you can use.

### RecordedOnDecorator

Each message needs a `RecordedOn` time. The `RecordedOnDecorator` is needed so that this is added to the message.
This decorator needs a [clock](clock.md) implementation.

```php
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Clock\SystemClock;
use Patchlevel\EventSourcing\EventBus\Decorator\RecordedOnDecorator;

final class OnSystemRecordedDecorator implements MessageDecorator
{
public function __invoke(Message $message): Message
{
return $message->withCustomHeader('system', 'accounting_system');
}
}
$clock = new SystemClock();
$decorator = new RecordedOnDecorator($clock);
```

!!! note
!!! warning

The Message is immutable, for more information look up [here](event_bus.md#message).
A `RecordedOn` time must always be created.
Either this decorator must always be added or an appropriate replacement must be provided.

!!! tip
### SplitStreamDecorator

You can also set multiple headers with `withCustomHeaders` which expects an hashmap.
In order to use the [split stream](split_stream.md) feature, the `SplitStreamDecorator` must be added.

```php
use Patchlevel\EventSourcing\EventBus\Decorator\SplitStreamDecorator;
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory;

$eventMetadataFactory = new AttributeEventMetadataFactory();
$decorator = new SplitStreamDecorator($eventMetadataFactory);
```

## Use own decorator
### ChainMessageDecorator

To use your own message decorator, you have to pass it to the `DefaultRepositoryManager`.
To use multiple decorators at the same time, one can use the `ChainMessageDecorator`.

```php
use Patchlevel\EventSourcing\EventBus\Decorator\ChainMessageDecorator;

$decorator = new ChainMessageDecorator([
$decorator1,
$decorator2,
]);
```

## Use decorator

To use the message decorator, you have to pass it to the `DefaultRepositoryManager`.

```php
use Patchlevel\EventSourcing\EventBus\Decorator\ChainMessageDecorator;
Expand All @@ -40,7 +62,7 @@ use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;

$decorator = new ChainMessageDecorator([
new RecordedOnDecorator($clock),
new OnSystemRecordedDecorator()
new SplitStreamDecorator($eventMetadataFactory)
]);

$repositoryManager = new DefaultRepositoryManager(
Expand All @@ -56,10 +78,35 @@ $repository = $repositoryManager->get(Profile::class);

!!! warning

We also use the decorator to fill in the `recordedOn` time.
If you want to add your own decorator, then you need to make sure to add the `RecordedOnDecorator` as well.
You can e.g. solve with the `ChainMessageDecorator`.
We also use the decorator to fill in the `RecordedOn` time.
If you want to add your own decorator or the SplitStreamDecorator,
then you need to make sure to add the `RecordedOnDecorator` as well.

!!! note

You can find out more about repository [here](repository).

## Create own decorator

You can also use this feature to add your own metadata to your events. For this the have an extra methods on `Message`
to add data `withCustomHeader` and to read this data later on `customHeader`.

```php
use Patchlevel\EventSourcing\EventBus\Message;

final class OnSystemRecordedDecorator implements MessageDecorator
{
public function __invoke(Message $message): Message
{
return $message->withCustomHeader('system', 'accounting_system');
}
}
```

!!! note

You can find out more about repository [here](repository).
The Message is immutable, for more information look up [here](event_bus.md#message).

!!! tip

You can also set multiple headers with `withCustomHeaders` which expects an hashmap.

0 comments on commit 1201de1

Please sign in to comment.