-
Notifications
You must be signed in to change notification settings - Fork 0
Command Bus
Pau F. Grau edited this page Jan 10, 2021
·
2 revisions
We use the command bus for all use cases need be executed with transaction
We use the follow open source packages:
- https://tactician.thephpleague.com/plugins/container/
- https://tactician.thephpleague.com/plugins/doctrine/
If you want add a new command you need do the follow steps:
- Add your command handler on CommandBusFactory::map
- Configure your command handler on CommandBusProvider
Example of use:
CLI:
...
$command = new ImportAuthorsCommand($data);
$this->commandBus->dispatch($command);
...
...
public function __invoke(ImportAuthorsCommand $command): void
{
$collection = [];
foreach ($command->data() as $item) {
Assert::keyExists($item, 'author');
$author = Author::create($item['author']);
if (isset($collection[$author->id()])) {
continue;
}
$collection[$author->id()] = $author->id();
$this->eventBus->publish(...$author->pullDomainEvents());
}
}
...