Skip to content

Commit

Permalink
Events are string references
Browse files Browse the repository at this point in the history
We can't return an Event object for the string given since it's using a static `dispatch` method.
  • Loading branch information
boekkooi-lengoo committed Jul 7, 2022
1 parent 9e4c040 commit ee4fb5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ private function setAccountConfig(string $key, array $config, array $default_con
* @param $config
*/
protected function setEventsFromConfig($config): void {
$this->events = ClientManager::get("events");
$events = ClientManager::get("events");
if(isset($config['events'])){
foreach($config['events'] as $section => $events) {
$this->events[$section] = array_merge($this->events[$section], $events);
$events[$section] = array_merge($events[$section], $events);
}
}
$this->setEvents($events);
}

/**
Expand Down
24 changes: 14 additions & 10 deletions src/Traits/HasEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,31 @@ trait HasEvents {
/**
* Event holder
*
* @var array $events
* @var array<string, array<string, string>> $events
*/
protected $events = [];

/**
* Set a specific event
* @param $section
* @param $event
* @param $class
*/
public function setEvent($section, $event, $class): void {
public function setEvent(string $section, string $event, string $class): void {
if (isset($this->events[$section])) {
$this->events[$section][$event] = $class;
}
}

/**
* Set all events
* @param $events
* @param array<string, array<string, string>> $events
*/
public function setEvents($events): void {
foreach($events as $section => $sectionEvents) {
assert(is_string($section));
foreach($sectionEvents as $event => $class) {
assert(is_string($event));
assert(is_string($class) && is_a($class, Event::class, true));
}
}
$this->events = $events;
}

Expand All @@ -55,10 +59,10 @@ public function setEvents($events): void {
* @param $section
* @param $event
*
* @return Event
* @return string
* @throws EventNotFoundException
*/
public function getEvent($section, $event): Event {
public function getEvent($section, $event): string {
if (isset($this->events[$section])) {
return $this->events[$section][$event];
}
Expand All @@ -68,10 +72,10 @@ public function getEvent($section, $event): Event {
/**
* Get all events
*
* @return array
* @return array<string, array<string, string>>
*/
public function getEvents(): array {
return $this->events;
}

}
}

0 comments on commit ee4fb5f

Please sign in to comment.