bruno-barros / w.eloquent-bus by bruno-barros

w.eloquent Command Bus Pattern.
13
0
1
Package Data
Maintainer Username: bruno-barros
Maintainer Contact: brunodanca@gmail.com (Bruno Barros)
Package Create Date: 2015-01-13
Package Last Update: 2015-01-14
Language: PHP
License: GPL-2.0+
Last Refreshed: 2024-11-17 03:04:16
Package Statistics
Total Downloads: 13
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

w.eloquent-bus

Command Bus for w.eloquent project.

Build Status

Installation

Update your composer: "bruno-barros/w.eloquent-bus": "dev-master"

Set the service provider: 'Weloquent\Bus\BusServiceProvider'

Run: composer update

How to use it

Create your command and handler.

// The command. Just a DTO.
class DoSomethingCommand {
	
	public $property = 'default value';
	
}

// On same folder, the handler.
class DoSomethingCommandHandler implements Weloquent\Bus\Contracts\CommandHandler {
	
	public function handler($command){
		
		// do whatever you need
	
	}
	
}

Use the trait and call the execute method.

class MyClass {

	use Weloquent\Bus\CommanderTrait;
	
	public function myMethod()
	{
		$input = ['property' => 'some value'];
					
		$this->execute(new Your\Namespace\DoSomething, $input);
	
	}
}

Or leave the commander handle the input if it exists on GET or POST array;

class MyClass {

	use Weloquent\Bus\CommanderTrait;
	
	// From a POST
	public function myMethod()
	{						
		$this->execute(new Your\Namespace\DoSomething);
	
	}
}

Decorators

You can decorate the command object (DTO).

Look:

  • The decorator must implements Weloquent\Bus\Contracts\CommandHandler.

  • The decorator should return the command object. Can be the original, or modified one.

// Decorator
class DecoratorCommandHandler implements Weloquent\Bus\Contracts\CommandHandler {
        
        public function handler($command)
        {	
            // apply any modification...
            
            return $command;    		
        }
    }


// Decorating
class MyClass {

	use Weloquent\Bus\CommanderTrait;
	
	// From a POST
	public function myMethod()
	{						
		$decorator = ['Your\Namespace\DecoratorCommandHandler'];
	
		$this->execute(new Your\Namespace\DoSomething, null, $decorator);
	
	}
}