2017 © Pedro Peláez
 

symfony-bundle command-bus-bundle

Handle Commands with CommandHandlers through a CommandBus

image

tactics/command-bus-bundle

Handle Commands with CommandHandlers through a CommandBus

  • Monday, May 14, 2018
  • by bartru
  • Repository
  • 12 Watchers
  • 1 Stars
  • 6,107 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

SimpleCommandBus

Build Status Scrutinizer Code Quality, (*1)

Say we have a command called RegisterUser., (*2)

<?php

use Pringles\DomainBundle\CommandBus\Command;

class RegisterUser implements Command
{
    public $firstname;
    public $lastname;
}

And we want to handle that command., (*3)

<?php

use Pringles\DomainBundle\CommandBus\CommandHandler;

class RegisterUserHandler implements CommandHandler
{
    private $personRepository;

    public function __construct(PersonRepository $personRepository)
    {
        $this->personRepository = $personRepository;
    }

    public function handle(RegisterUser $registerUser)
    {
        $person = Person::register($registerUser->firstname, $registerUser->lastname);
    }
}

We can setup the SimpleCommandBus, register the handler and handle the command., (*4)

<?php

use Pringles\DomainBundle\CommandBus\SimpleCommandBus;

function someController()
{
    $bus = new SimpleCommandBus(new ShortNameStrategy());
    $bus->registerHandler(new RegisterUserHandler($personRepository));

    $cmd = new RegisterUser;
    $cmd->firstname = 'Aaron';
    $cmd->lastname = 'Muylaert';

    $bus->handle($cmd);
}

SimpleCommandBus finds handlers based on their name. A command named Test requires a registered handler called TestHandler. If no handler is found, nothing happens., (*5)

Oh, one small rule, command handlers are not allowed to return values., (*6)

There is a command bus service called command_bus. You can register a handler by registering your handler as a service and tagging the service as command_handler. Using it looks like this:, (*7)

<?php

$cmd = new Test;
$cmd->value = 'Foo';

$this->get('command_bus')->handle($cmd);

\m/, (*8)

The Versions

14/05 2018

dev-master

9999999-dev

Handle Commands with CommandHandlers through a CommandBus

  Sources   Download

MIT

The Requires

 

by Aaron Muylaert
by Jochen Janssens
by Bart Ruysseveldt

bundle symfony

14/05 2018

v1.1.2

1.1.2.0

Handle Commands with CommandHandlers through a CommandBus

  Sources   Download

MIT

The Requires

 

by Aaron Muylaert
by Jochen Janssens
by Bart Ruysseveldt

bundle symfony

08/02 2016

v1.1.1

1.1.1.0

Handle Commands with CommandHandlers through a CommandBus

  Sources   Download

MIT

The Requires

 

by Aaron Muylaert
by Jochen Janssens
by Bart Ruysseveldt

bundle symfony

22/01 2016

v1.1.0

1.1.0.0

Handle Commands with CommandHandlers through a CommandBus

  Sources   Download

MIT

The Requires

 

by Aaron Muylaert
by Jochen Janssens
by Bart Ruysseveldt

bundle symfony

10/12 2014

v1.0.1

1.0.1.0

Handle Commands with CommandHandlers through a CommandBus

  Sources   Download

MIT

The Requires

 

by Aaron Muylaert
by Jochen Janssens
by Bart Ruysseveldt

bundle symfony

08/12 2014

v1.0.0

1.0.0.0

Handle Commands with CommandHandlers through a CommandBus

  Sources   Download

MIT

The Requires

 

by Aaron Muylaert
by Jochen Janssens
by Bart Ruysseveldt

bundle symfony