mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-24 23:28:40 +00:00
Add regex group trigger support
This commit is contained in:
parent
d47f3aa19d
commit
7f603656f3
|
|
@ -78,10 +78,35 @@ final class EventManager
|
|||
*/
|
||||
public function trigger(string $group, string $id = '', $data = null) : bool
|
||||
{
|
||||
if (!isset($this->callbacks[$group])) {
|
||||
return false;
|
||||
if (isset($this->callbacks[$group])) {
|
||||
return $this->triggerSingleEvent($group, $id, $data);
|
||||
}
|
||||
|
||||
$allGroups = \array_keys($this->callbacks);
|
||||
$result = false;
|
||||
|
||||
foreach ($allGroups as $match) {
|
||||
if(\preg_match('~^' . $group . '$~', $match) === 1) {
|
||||
$result = $result || $this->triggerSingleEvent($match, $id, $data);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger event
|
||||
*
|
||||
* @param string $group Name of the event
|
||||
* @param string $id Sub-requirement for event
|
||||
* @param mixed $data Data to pass to the callback
|
||||
*
|
||||
* @return bool Returns true on sucessfully triggering the event, false if the event couldn't be triggered which also includes sub-requirements missing.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function triggerSingleEvent(string $group, string $id = '', $data = null) : bool
|
||||
{
|
||||
if (isset($this->groups[$group])) {
|
||||
$this->groups[$group][$id] = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user