Process register
public processRegister ( |
||
$session | ||
$msg | Thruway\Message\RegisterMessage | |
Результат | boolean |
public function testLeave() { $session = $this->getMockBuilder('\\Thruway\\Session')->disableOriginalConstructor()->getMock(); $session->expects($this->once())->method("sendMessage")->with($this->isInstanceOf('\\Thruway\\Message\\RegisteredMessage')); $registerMsg = new \Thruway\Message\RegisterMessage(\Thruway\Common\Utils::getUniqueId(), [], 'test_procedure'); $this->_proc->processRegister($session, $registerMsg); $this->assertEquals(1, count($this->_proc->getRegistrations())); $this->_proc->leave($session); $this->assertEquals(0, count($this->_proc->getRegistrations())); }
/** * process RegisterMessage * * @param \Thruway\Session $session * @param \Thruway\Message\RegisterMessage $msg */ private function processRegister(Session $session, RegisterMessage $msg) { // check for valid URI if (!Utils::uriIsValid($msg->getProcedureName())) { $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.invalid_uri')); return; } //Check to see if the procedure is already registered /** @var Procedure $procedure */ if (isset($this->procedures[$msg->getProcedureName()])) { $procedure = $this->procedures[$msg->getProcedureName()]; } else { $procedure = new Procedure($msg->getProcedureName()); $this->procedures[$msg->getProcedureName()] = $procedure; } if ($procedure->processRegister($session, $msg)) { // registration succeeded // make sure we have the registration in the collection // of registrations for this session if (!$this->registrationsBySession->contains($session)) { $this->registrationsBySession->attach($session, []); } $registrationsForThisSession = $this->registrationsBySession[$session]; if (!in_array($procedure, $registrationsForThisSession)) { array_push($registrationsForThisSession, $procedure); $this->registrationsBySession[$session] = $registrationsForThisSession; } } }