예제 #1
0
 /**
  * Dispatch the message to all corresponding listeners.
  * @param \Brickoo\Component\Messaging\Message $message
  * @throws \Brickoo\Component\Messaging\Exception\MaxRecursionDepthReachedException
  * @return \Brickoo\Component\Messaging\MessageDispatcher
  */
 public function dispatch(Message $message)
 {
     $messageName = $message->getName();
     if (!$this->listenerCollection->hasListeners($messageName)) {
         return $this;
     }
     if ($this->messageRecursionDepthList->isDepthLimitReached($messageName)) {
         throw new MaxRecursionDepthReachedException($messageName, $this->messageRecursionDepthList->getRecursionDepth($messageName));
     }
     $this->messageRecursionDepthList->increaseDepth($messageName);
     $this->processMessage($message, $this->listenerCollection->getListeners($messageName));
     $this->messageRecursionDepthList->decreaseDepth($messageName);
     return $this;
 }