Command Handlers
Once you create a Command, you need to create a Command Handler to handle that command. Command Handlers do NOT return any results.
<?php
use SonsOfPHP\Component\Cqrs\Command\CommandMessageHandlerInterface;
final class ExampleCommandHandler implements CommandMessageHandlerInterface
{
}
Getting the Command to the Command Handler
Attention
The CommandMessageBus
reqires the sonsofphp/cqrs-symfony
package.
You can use Messenger to process commands. If you're using Messenger as a
standalone component, inject your MessageBus
object into the
CommandMessageBus
.
<?php
use SonsOfPHP\Bridge\Symfony\Cqrs\CommandMessageBus;
$commandBus = new CommandMessageBus($messageBus);
If using the Symfony Framework, it's even easier. You'll just need to update
your services.yaml
file.
Note
You will need to configure Messenger to have multiple buses. command.bus
is the name of the bus that was configured to process commands.
Using the CommandMessageBus
is easy as well.