Esempio n. 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;
 }
 /** @covers Brickoo\Component\Messaging\ListenerCollection::hasListeners */
 public function testHasListeners()
 {
     $messageName = "test.listener";
     $listenerCollection = new ListenerCollection();
     $this->assertFalse($listenerCollection->hasListeners($messageName));
     $listenerCollection->add(new MessageListener($messageName, 0, function () {
     }));
     $this->assertTrue($listenerCollection->hasListeners($messageName));
 }