Initial commit

This commit is contained in:
2024-03-01 14:34:14 +01:00
commit befe5f5d59
15 changed files with 711 additions and 0 deletions

40
src/Command.php Normal file
View 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;
});
}
}