Other Packages


Command Bus Overview

The Command bus is a simple concept for requesting your domain to perform an operation. The bus takes a request and make sure that is goes to where it needs to.

Commands go into the command bus. The command bus hands it off to a handler and then handler does the job. The command represents a method/use case your application can performs.

The command bus makes up a key part of CQRS acting as the interface to the domain.

The beauty is commands can be fired from many different transport layers (http/command line/api/event listener).

Command handlers tend to conversion from a simple message into a language the domain can understand. Handlers load the domains dependencies, covert primitive types to domain types and perform the action.

To Learn more about command bus

Some resources about the concepts of a command bus

Simple Example


 class ExampleCommand extends SmoothPhp\CommandBus\BaseCommand
     public function __construct($exampleField)
         $this->exampleField = $exampleField;
     public function getExampleField()
         return $this->exampleField;

Command Handler

class ExampleCommandHandler
     * @param ExampleCommand $exampleCommand
    public function handle(ExampleCommand $exampleCommand)

Command Bus (the glue)

$commandTranslator = new  SmoothPhp\CommandBus\SimpleCommandTranslator();
$handlerResolver = SmoothPhp\CommandBus\SimpleCommandHandlerResolver();

$commandBus = new SmoothPhp\CommandBus\SimpleCommandBus($commandTranslator,$handlerResolver);

$commandBus->execute(new ExampleCommand('Hello World'));