diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 4825ee7f4..43533aeaf 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -1730,6 +1730,8 @@ class DataMapperAbstract implements DataMapperInterface } if (!isset($obj)) { + // todo: implement solution for classes with constructor arguments + // maybe implement a factory pattern for every datamapper model $obj = new $class(); } diff --git a/Event/EventManager.php b/Event/EventManager.php index e76b350b6..735f121bb 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -62,9 +62,13 @@ final class EventManager public function __construct(Dispatcher $dispatcher = null) { $this->dispatcher = $dispatcher ?? new class { - function dispatch($func, array $data) + public function dispatch($func, $data) { - $func(...$data); + if (\is_array($data)) { + $func(...$data); + } else { + $func($data); + } } }; } @@ -88,10 +92,8 @@ final class EventManager $hooks = include $path; foreach ($hooks as $group => $hook) { - foreach ($hook['callback'] as $callbacks) { - foreach ($callbacks as $callback) { - $this->attach($group, $callback, $hook['remove'] ?? false, $hook['reset'] ?? true); - } + foreach ($hook['callback'] as $callback) { + $this->attach($group, $callback, $hook['remove'] ?? false, $hook['reset'] ?? true); } } @@ -142,7 +144,7 @@ final class EventManager $result = false; foreach ($allGroups as $match) { - if (\preg_match('~^' . $group . '$~', $match) === 1) { + if (\preg_match('~^' . $match . '$~', $group) === 1) { $result = $result || $this->triggerSingleEvent($match, $id, $data); } } @@ -169,7 +171,11 @@ final class EventManager if (!$this->hasOutstanding($group)) { foreach ($this->callbacks[$group]['callbacks'] as $func) { - $this->dispatcher->disptach($func, ...$data); + if (\is_array($data)) { + $this->dispatcher->dispatch($func, ...$data); + } else { + $this->dispatcher->dispatch($func, $data); + } } if ($this->callbacks[$group]['remove']) { @@ -195,6 +201,10 @@ final class EventManager */ private function reset(string $group) : void { + if (!isset($this->groups[$group])) { + return; + } + foreach ($this->groups[$group] as $id => $ok) { $this->groups[$group][$id] = false; } diff --git a/tests/Event/EventManagerTest.php b/tests/Event/EventManagerTest.php index 05be07990..832c8567a 100644 --- a/tests/Event/EventManagerTest.php +++ b/tests/Event/EventManagerTest.php @@ -40,7 +40,7 @@ class EventManagerTest extends \PHPUnit\Framework\TestCase $event = new EventManager(); self::assertTrue($event->attach('group', function() { return true; }, false, false)); - self::assertFalse($event->attach('group', function() { return true; }, false, false)); + self::assertTrue($event->attach('group', function() { return true; }, false, false)); self::assertEquals(1, $event->count()); }