Initial commit
This commit is contained in:
40
src/Command.php
Normal file
40
src/Command.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\React\CommandBus;
|
||||
|
||||
use React\Promise\Deferred;
|
||||
use React\Promise\Promise;
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Command
|
||||
{
|
||||
/** @var string $name The command name */
|
||||
private string $name;
|
||||
|
||||
/** @var callable $handler The handler */
|
||||
private $handler;
|
||||
|
||||
public function __construct(string $name, callable $handler)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->handler = $handler;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function call(Context $context): PromiseInterface
|
||||
{
|
||||
return new Promise(function (callable $resolve) use ($context) {
|
||||
$resolve(call_user_func($this->handler, $context));
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user