This commit is contained in:
as2252258@163.com
2021-03-24 01:00:43 +08:00
parent bdbd91d8ab
commit 305d250195
+37
View File
@@ -25,6 +25,9 @@ class Producer extends Component
private array $consumers = [];
private array $cmds = [];
/**
* @param string $name
* @param array $handler
@@ -40,6 +43,40 @@ class Producer extends Component
}
/**
* @param string $name
* @param array $handler
* @param array $node
*/
public function addConsumer(string $cmd, array $handler)
{
$class = get_class($handler[0]);
if (!isset($this->classAlias[$class])) {
return;
}
$name = $this->classAlias[$class];
$this->cmds[$name . '.' . $cmd] = $handler;
}
/**
* @param $cmd
* @param mixed ...$params
* @return false|mixed
*/
public function dispatch($cmd, mixed ...$params)
{
$handler = $this->cmds[$cmd] ?? null;
if (empty($handler)) {
return false;
}
return call_user_func($handler, ...$params);
}
/**
* @param $name
* @return mixed