dispatcher = $locator; return $this; } /** * @return EventDispatcherInterface */ public function getDispatcher() { if ($this->dispatcher instanceof EventDispatcherInterface) { return $this->dispatcher; } if (null === $this->dispatcher) { throw new \LogicException('Dispatcher locator was not set'); } $dispatcher = call_user_func($this->dispatcher); if (!$dispatcher instanceof EventDispatcherInterface) { throw new \LogicException(sprintf( 'Expects locator to return instance of "%s", got "%s"', EventDispatcherInterface::class, is_object($dispatcher) ? get_class($dispatcher) : gettype($dispatcher) )); } $this->dispatcher = $dispatcher; return $this->dispatcher; } /** * @see \Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch */ public function dispatch($eventName, Event $event = null) { return $this->getDispatcher()->dispatch($eventName, $event); } }