diff --git a/Event/EventManager.php b/Event/EventManager.php index b55967b78..9d094dbbb 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -139,6 +139,7 @@ final class EventManager implements \Countable } $this->callbacks[$group]['callbacks'][] = $callback; + $this->addGroup($group, ''); return true; } @@ -160,24 +161,28 @@ final class EventManager implements \Countable $idIsRegex = \stripos($id, '/') === 0; $groups = []; - if ($groupIsRegex) { - foreach ($this->groups as $groupName => $value) { + foreach ($this->groups as $groupName => $value) { + if ($groupIsRegex) { if (\preg_match($group, $groupName) === 1) { $groups[$groupName] = []; } + } elseif (\preg_match($groupName, $group) === 1) { + $groups[$groupName] = []; } - } else { - $groups[$group] = []; } foreach ($groups as $groupName => $groupValues) { - if ($idIsRegex) { - foreach ($this->groups[$groupName] as $idName => $value) { + foreach ($this->groups[$groupName] as $idName => $value) { + if ($idIsRegex) { if (\preg_match($id, $idName) === 1) { $groups[$groupName][] = $idName; } + } elseif ($idName !== '' && \preg_match($idName, $id) === 1) { + $groups[$groupName][] = $id; } - } else { + } + + if (empty($groups[$groupName])) { $groups[$groupName][] = $id; } } diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index a012a70fc..f5a30d335 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -262,9 +262,9 @@ abstract class ModuleAbstract */ protected function createModel(int $account, $obj, string $mapper, string $trigger, string $ip) : void { - $this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', $obj); + $this->app->eventManager->triggerSimilar('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', $obj); $id = $mapper::create($obj); - $this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', [ + $this->app->eventManager->triggerSimilar('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', [ $account, null, $obj, StringUtils::intHash($mapper), 0, @@ -291,9 +291,9 @@ abstract class ModuleAbstract protected function createModels(int $account, array $objs, string $mapper, string $trigger, string $ip) : void { foreach ($objs as $obj) { - $this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', $obj); + $this->app->eventManager->triggerSimilar('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', $obj); $id = $mapper::create($obj); - $this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', [ + $this->app->eventManager->triggerSimilar('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-create', '', [ $account, null, $obj, StringUtils::intHash($mapper), 0, @@ -321,14 +321,14 @@ abstract class ModuleAbstract */ protected function updateModel(int $account, $old, $new, $mapper, string $trigger, string $ip) : void { - $this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', $old); + $this->app->eventManager->triggerSimilar('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', $old); $id = 0; if (\is_string($mapper)) { $id = $mapper::update($new); } elseif ($mapper instanceof \Closure) { $mapper(); } - $this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', [ + $this->app->eventManager->triggerSimilar('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', [ $account, $old, $new, StringUtils::intHash(\is_string($mapper) ? $mapper : \get_class($mapper)), 0, @@ -354,9 +354,9 @@ abstract class ModuleAbstract */ protected function deleteModel(int $account, $obj, string $mapper, string $trigger, string $ip) : void { - $this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-delete', '', $obj); + $this->app->eventManager->triggerSimilar('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-delete', '', $obj); $id = $mapper::delete($obj); - $this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-delete', '', [ + $this->app->eventManager->triggerSimilar('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-delete', '', [ $account, $obj, null, StringUtils::intHash($mapper), 0, @@ -384,9 +384,9 @@ abstract class ModuleAbstract */ protected function createModelRelation(int $account, $rel1, $rel2, string $mapper, string $field, string $trigger, string $ip) : void { - $this->app->eventManager->trigger('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-relation', '', $rel1); + $this->app->eventManager->triggerSimilar('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-relation', '', $rel1); $mapper::createRelation($field, $rel1, $rel2); - $this->app->eventManager->trigger('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-relation', '', [ + $this->app->eventManager->triggerSimilar('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-relation', '', [ $account, $rel1, $rel2, StringUtils::intHash($mapper), 0,