2017 © Pedro Peláez
 

library commander

A simple command bus.

image

tomwright/commander

A simple command bus.

  • Friday, November 11, 2016
  • by TomWright
  • Repository
  • 1 Watchers
  • 0 Stars
  • 342 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Commander

Build Status Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License, (*1)

Usage

You need a Command and a CommandHandler., (*2)

Let's say we have a command class stored in app/commanding/command/RegisterUserCommand.php., (*3)

namespace App\Commanding\Command;

class RegisterUserCommand extends \TomWright\Commander\Command\Command
{
    protected $username;
    protected $password;

    public function setUsername($username)
    {
        $this->username = $username;
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function setPassword($password)
    {
        $this->password = $password;
    }

    public function getPassword()
    {
        return $this->password;
    }
}

Let's also assume we have a command handler class stored in app/commanding/handler/RegisterUserHandler.php., (*4)

namespace App\Commanding\Handler;

class RegisterUserHandler implements \TomWright\Commander\Handler\HandlerInterface
{   
    public function handle(\TomWright\Commander\Command\CommandInterface $command)
    {
        echo "Registering user \"{$command->getUsername()}\" with password \"{$command->getPassword()}\".";
    }
}

Now we need to add a Command Handler namespace so as the CommandBus knows where to look for the handlers., (*5)

$bus = \TomWright\Commander\CommandBus::getInstance();
$bus->addHandlerNamespace('\\App\\Commanding\\Handler');

Now whenever we want to register a new user, all we have to do is the following:, (*6)

$bus = \TomWright\Commander\CommandBus::getInstance();
$command = new \App\Commanding\Command\RegisterUserCommand();
$command->setUsername('Some user');
$command->setPassword('Somepassword123');
$bus->handle($command);

Remember - a Command is an action and not a notification. If you are looking for a notification/event handler see TomWright/Eventing., (*7)

The Versions

11/11 2016

dev-master

9999999-dev

A simple command bus.

  Sources   Download

The Requires

 

24/03 2016

1.0.2

1.0.2.0

A simple command bus.

  Sources   Download

The Requires

 

23/03 2016

1.0.1

1.0.1.0

A simple command bus.

  Sources   Download

The Requires

 

23/03 2016

1.0.0

1.0.0.0

A simple command bus.

  Sources   Download

The Requires