'MyCommandHandler', ]; final class Mailer { } final class MyCommand { public $name; public $emailAddress; public function __construct($name, $emailAddress) { $this->name = $name; $this->emailAddress = $emailAddress; } } final class MyCommandHandler { private $mailer; public function __construct(Mailer $mailer) { $this->mailer = $mailer; } public function handleMyCommand($command) { $format = <<name, $command->emailAddress); } } $containerLocator = new ContainerLocator( (new Container())->delegate(new ReflectionContainer()), $mapping ); $handlerMiddleware = new CommandHandlerMiddleware( new ClassNameExtractor(), $containerLocator, new HandleClassNameInflector() ); $commandBus = new CommandBus([$handlerMiddleware]); $command = new MyCommand('Joe Bloggs', 'j.bloggs@theinternet.com'); echo '
';
try {
    $commandBus->handle($command);
} catch (\Exception $e) {
    echo $e->getMessage();
    echo '
';
    print_r($e->getTraceAsString());
    echo '
'; }