-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
In your controller:
$form->handleRequest($request);
if (!$form->isValid()) {
throw new HttpException(406, (string) new FormErrorsRepresentation($form->getErrors()));
}
try {
// Send the message
$this->bookingService->payBooking($command);
You use a service and pass a command as parameter.
This other Symfony DDD exmaple uses a CommandHandler:
$form->handleRequest($request);
if ($form->isValid()) {
$trip = $this->get('command_handler')->execute($form->getData());
return new Response('ok');
}
In that sample payBooking would use a Use Case.
Prons:
- Common logic in Command execution as validation and event dispatcher.
- Avoid fat services, your bookingService would be replace with some UseCase classes.
This other sample uses commandBus instead of CommandHandler:
https://github.com/tyx/cqrs-php-sandbox/blob/master/src/Afsy/UI/Controller/GameCommandController.php
I am trying to figure out which is the best option to implement DDD in a project with Symfony. Perpahs a mixing of them or it depends on the domain. What do you think?
Metadata
Metadata
Assignees
Labels
No labels