bruno-barros/w.eloquent-bus
Composer 安装命令:
composer create-project bruno-barros/w.eloquent-bus
包简介
w.eloquent Command Bus Pattern.
README 文档
README
Command Bus for w.eloquent project.
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);
}
}
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2015-01-14