Skip to content


All Commands must implement the CommandMessageInterface.

Basic Command

Simple Commands can be created quickly and easily.


use SonsOfPHP\Component\Cqrs\Command\CommandMessageInterface;

final class SendPasswordResetEmailToUser implements CommandMessageInterface
    public function __construct(
        public readonly string $userId,
    ) {
        $this->userId = $userId;

Options Resolver Command


The AbstractOptionsResolverCommand reqires the sonsofphp/cqrs-symfony package.

The Options Resolver Command allows you to create more complex commands. For example.


use SonsOfPHP\Bridge\Symfony\Cqrs\Command\AbstractOptionsResolverCommandMessage;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class SendPasswordResetEmailToUser extends AbstractOptionsResolverCommandMessage
    protected function configureOptions(OptionsResolver $resolver): void
            ->allowedValues(function ($value) {
                return $value > 0;


To use the command, you just create a new instance of the command.


$command = new SendPasswordResetEmailToUser(['user_id' => 1234]);

// ...

// Get an option
$userId = $command->getOption('user_id');

// Get ALL options
$options = $command->getOptions():

// Check if option exists