modify
This commit is contained in:
@@ -25,6 +25,9 @@ class Producer extends Component
|
|||||||
private array $consumers = [];
|
private array $consumers = [];
|
||||||
|
|
||||||
|
|
||||||
|
private array $cmds = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $handler
|
* @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
|
* @param $name
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|||||||
Reference in New Issue
Block a user