-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d0ee16
commit 91e68f9
Showing
5 changed files
with
171 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Processor | ||
|
||
The `processor` is a kind of [event bus](./event_bus.md) listener that can execute actions on certain events. | ||
A process can be for example used to send an email when a guest is checked in: | ||
|
||
```php | ||
namespace App\Domain\Hotel\Listener; | ||
|
||
use App\Domain\Hotel\Event\GuestIsCheckedIn; | ||
use Patchlevel\EventSourcing\Aggregate\AggregateChanged; | ||
use Patchlevel\EventSourcing\EventBus\Listener; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\Mime\Email; | ||
|
||
final class SendCheckInEmailListener implements Listener | ||
{ | ||
private MailerInterface $mailer; | ||
|
||
private function __construct(MailerInterface $mailer) | ||
{ | ||
$this->mailer = $mailer; | ||
} | ||
|
||
public function __invoke(AggregateChanged $event): void | ||
{ | ||
if (!$event instanceof GuestIsCheckedIn) { | ||
return; | ||
} | ||
|
||
$email = (new Email()) | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->subject('Guest is checked in') | ||
->text(sprintf('A new guest named "%s" is checked in', $event->guestName())); | ||
|
||
$this->mailer->send($email); | ||
} | ||
} | ||
``` | ||
|
||
If you have the symfony default service setting with `autowire`and `autoconfiger` enabled, | ||
the processor is automatically recognized and registered at the `Listener` interface. | ||
Otherwise you have to define the processor in the symfony service file: | ||
|
||
```yaml | ||
services: | ||
App\Domain\Hotel\Listener\SendCheckInEmailListener: | ||
tags: | ||
- event_sourcing.processor | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
# Tools | ||
|
||
The bundle offers even more DX tools, which are listed here. | ||
|
||
## Show events | ||
|
||
You can display all events for a specific aggregate: | ||
|
||
```bash | ||
bin/console event-sourcing:show aggregate id | ||
``` | ||
|
||
## Watch events | ||
|
||
dev config: | ||
There is also a watch server, because you can start to see all events in real time. | ||
To do this, you have to add the following configuration for the dev environment: | ||
|
||
```yaml | ||
patchlevel_event_sourcing: | ||
watch_server: | ||
enabled: true | ||
``` | ||
> :warning: Use this configuration for dev purposes only! | ||
There is then a new command to start the watch server: | ||
```bash | ||
bin/console event-sourcing:watch | ||
``` | ||
``` | ||
|
||
> :book: The command can be terminated with `ctrl+c` or `control+c`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters