Menu


Commands


EventBus


Other Packages

Papertrail

Command Bus Translator


Once the command bus has received the command it needs to work out the location of the handler.

interface CommandTranslator
{
    /**
     * @param mixed $command
     * @return string
     */
    public function toCommandHandler($command);
}

The command bus relies on a implementation of the CommandTranslator interface. Which simple takes the command and works out the name of the handler class.

Simplest Method

We provide the simplest method which suffix the command class name with Handler SmoothPhp\CommandBus\SimpleCommandTranslator

$handler = get_class($command) . 'Handler'

e.g. Amce\Members\ChangeUserEmail -> Amce\Members\ChangeUserEmailHandler

You are free to change the translator to build more complex methods of translation

Implementing your own


To implement your own implement SmoothPhp\Contracts\CommandBus\CommandTranslator

interface CommandTranslator
{
    /**
     * @param mixed $command
     * @return string
     * @throws HandlerNotFound
     */
    public function toCommandHandler($command);
}

If you can not resolve the handler throw SmoothPhp\CommandBus\Exception\HandlerNotFound