You are here

public function HookEventDispatcherManagerSpy::register in Hook Event Dispatcher 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/HookEventDispatcherManagerSpy.php \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy::register()
  2. 3.x tests/src/Unit/HookEventDispatcherManagerSpy.php \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy::register()

Throws

\Drupal\Tests\hook_event_dispatcher\Unit\TooManyEventsException

Overrides HookEventDispatcherManagerInterface::register

File

tests/src/Unit/HookEventDispatcherManagerSpy.php, line 46

Class

HookEventDispatcherManagerSpy
Class HookEventDispatcherManagerSpy.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit

Code

public function register(EventInterface $event) {
  $this->eventCount++;
  if ($this->eventCount > $this->maxEventCount) {
    throw new TooManyEventsException("Got {$this->eventCount} events, but only {$this->maxEventCount} are allowed");
  }
  $type = $event
    ->getDispatcherType();
  $this->registeredEvents[$type] = $event;
  if (isset($this->eventCallbacks[$type])) {
    $this->eventCallbacks[$type]($event);
  }
}