Thruway\Session::dispatchMessage PHP Method

dispatchMessage() public method

public dispatchMessage ( Thruway\Message\Message $message, string $eventNamePrefix = "" )
$message Thruway\Message\Message
$eventNamePrefix string
    public function dispatchMessage(Message $message, $eventNamePrefix = "")
    {
        if ($eventNamePrefix == "") {
            $this->lastInboundActivity = microtime(true);
            $this->messagesReceived++;
        }
        // this could probably become a constant inside the message itself
        $r = new \ReflectionClass($message);
        $shortName = $r->getShortName();
        if ($message instanceof HelloMessage) {
            $this->dispatcher->dispatch("Pre" . $shortName . "Event", new MessageEvent($this, $message));
        }
        $this->dispatcher->dispatch($eventNamePrefix . $shortName . "Event", new MessageEvent($this, $message));
    }

Usage Example

Example #1
0
 /**
  * @depends testJoin
  *
  * @param \Thruway\Session $session
  */
 public function testRegister(\Thruway\Session $session)
 {
     $realm = $session->getRealm();
     $registerMessage = new \Thruway\Message\RegisterMessage(\Thruway\Common\Utils::getUniqueId(), [], 'test_procedure');
     $session->dispatchMessage($registerMessage);
     $registrations = $realm->getDealer()->managerGetRegistrations()[0];
     $this->assertEquals(1, count($registrations));
     $this->assertEquals("test_procedure", $registrations[0]['name']);
     $this->assertInstanceOf('\\Thruway\\Message\\RegisteredMessage', $session->getTransport()->getLastMessageSent());
 }