allow event trigger passing

This commit is contained in:
Dennis Eichhorn 2022-03-11 23:17:38 +01:00
parent c20021464c
commit df89ee433e
2 changed files with 17 additions and 2 deletions

View File

@ -65,6 +65,7 @@ final class Dispatcher implements DispatcherInterface
public function dispatch(array | string | \Closure $controller, ...$data) : array public function dispatch(array | string | \Closure $controller, ...$data) : array
{ {
$views = []; $views = [];
$data = $data !== null ? \array_values($data) : null;
if (\is_array($controller) && isset($controller['dest'])) { if (\is_array($controller) && isset($controller['dest'])) {
if (!empty($controller['data'])) { if (!empty($controller['data'])) {

View File

@ -207,6 +207,12 @@ final class EventManager implements \Countable
} }
} }
if (!\is_array($data)) {
$data = [$data];
}
$data[':triggerGroup'] ??= $group;
$triggerValue = false; $triggerValue = false;
foreach ($groups as $groupName => $ids) { foreach ($groups as $groupName => $ids) {
foreach ($ids as $id) { foreach ($ids as $id) {
@ -244,10 +250,18 @@ final class EventManager implements \Countable
foreach ($this->callbacks[$group]['callbacks'] as $func) { foreach ($this->callbacks[$group]['callbacks'] as $func) {
if (\is_array($data)) { if (\is_array($data)) {
$this->dispatcher->dispatch($func, ...$data); $data[':triggerGroup'] ??= $group;
$data[':triggerId'] = $id;
} else { } else {
$this->dispatcher->dispatch($func, $data); $data = [
$data,
];
$data[':triggerGroup'] ??= $group;
$data[':triggerId'] = $id;
} }
$this->dispatcher->dispatch($func, ...$data);
} }
if ($this->callbacks[$group]['remove']) { if ($this->callbacks[$group]['remove']) {