_observerFactory = $observerFactory; $this->_appState = $appState; } /** * Dispatch event * * @param array $configuration * @param Observer $observer * @return void */ public function dispatch(array $configuration, Observer $observer) { /** Check whether event observer is disabled */ if (isset($configuration['disabled']) && true === $configuration['disabled']) { return; } if (isset($configuration['shared']) && false === $configuration['shared']) { $object = $this->_observerFactory->create($configuration['instance']); } else { $object = $this->_observerFactory->get($configuration['instance']); } $this->_callObserverMethod($object, $observer); } /** * @param \Magento\Framework\Event\ObserverInterface $object * @param Observer $observer * @return $this * @throws \LogicException */ protected function _callObserverMethod($object, $observer) { if ($object instanceof \Magento\Framework\Event\ObserverInterface) { $object->execute($observer); } elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) { throw new \LogicException( sprintf( 'Observer "%s" must implement interface "%s"', get_class($object), \Magento\Framework\Event\ObserverInterface::class ) ); } return $this; } }