/** * Lazy loads event handlers from the service container * * @param string $eventType The event type * * @return void */ protected function lazyLoad(string $eventType) { if (isset($this->serviceIds[$eventType])) { foreach ($this->serviceIds[$eventType] as $args) { list($serviceId, $method, $priority) = $args; $service = $this->container->get($serviceId); $key = $serviceId . '.' . $method; if (!isset($this->services[$eventType][$key])) { $this->addHandler($eventType, [$service, $method], $priority); } elseif ($service !== $this->services[$eventType][$key]) { parent::removeHandler($eventType, [$this->services[$eventType][$key], $method]); $this->addHandler($eventType, [$service, $method], $priority); } $this->services[$eventType][$key] = $service; } } }
public function test_that_remove_handler_does_not_error_when_handler_not_registered() { $this->dispatcher->removeHandler('foo', function () { }); $this->assertFalse($this->dispatcher->hasHandlers()); }