/** * process unregister * * @param \Thruway\Session $session * @param \Thruway\Message\UnregisterMessage $msg * @return bool */ public function processUnregister(Session $session, UnregisterMessage $msg) { for ($i = 0; $i < count($this->registrations); $i++) { /** @var Registration $registration */ $registration = $this->registrations[$i]; if ($registration->getId() == $msg->getRegistrationId()) { // make sure the session is the correct session if ($registration->getSession() !== $session) { $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, "wamp.error.no_such_registration")); //$this->manager->warning("Tried to unregister a procedure that belongs to a different session."); return false; } array_splice($this->registrations, $i, 1); // TODO: need to handle any calls that are hanging around $session->sendMessage(UnregisteredMessage::createFromUnregisterMessage($msg)); return true; } } $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_registration')); return false; }
/** * @param Session $session * @param UnregisterMessage $msg * @throws \Exception * @return Message */ private function processUnregister(Session $session, UnregisterMessage $msg) { //find the procedure by registration id $this->registrations->rewind(); while ($this->registrations->valid()) { $registration = $this->registrations->current(); if ($registration->getId() == $msg->getRegistrationId()) { $this->registrations->next(); // make sure the session is the correct session if ($registration->getSession() !== $session) { throw new \Exception("Tried to unregister a procedure that belongs to a different session."); } $this->manager->debug('Unegistered: ' . $registration->getProcedureName()); $this->registrations->detach($registration); return new UnregisteredMessage($msg->getRequestId()); } else { $this->registrations->next(); } } $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg); $this->manager->error('No registration: ' . $msg->getRegistrationId()); return $errorMsg->setErrorURI('wamp.error.no_such_registration'); }
/** * process UnregisterMessage * * @param \Thruway\Session $session * @param \Thruway\Message\UnregisterMessage $msg * @throws \Exception */ private function processUnregister(Session $session, UnregisterMessage $msg) { $registration = $this->getRegistrationById($msg->getRegistrationId()); if ($registration && $this->procedures[$registration->getProcedureName()]) { $procedure = $this->procedures[$registration->getProcedureName()]; if ($procedure) { if ($procedure->processUnregister($session, $msg)) { // Unregistration was successful - remove from this sessions // list of registrations if ($this->registrationsBySession->contains($session) && in_array($procedure, $this->registrationsBySession[$session])) { $registrationsInSession = $this->registrationsBySession[$session]; array_splice($registrationsInSession, array_search($procedure, $registrationsInSession), 1); } } } return; } // apparently we didn't find anything to unregister $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure')); }
/** * Create Unregisterd message from unregister message * * @param \Thruway\Message\UnregisterMessage $msg * @return \Thruway\Message\UnregisteredMessage */ public static function createFromUnregisterMessage(UnregisterMessage $msg) { return new UnregisteredMessage($msg->getRequestId()); }
/** * process UnregisterMessage * * @param \Thruway\Session $session * @param \Thruway\Message\UnregisterMessage $msg * @throws \Exception */ private function processUnregister(Session $session, UnregisterMessage $msg) { // we are going to assume that the registration only exists in one spot /** @var Procedure $procedure */ foreach ($this->procedures as $procedure) { /** @var Registration $registration */ $registration = $procedure->getRegistrationById($msg->getRegistrationId()); if ($registration) { if ($procedure->processUnregister($session, $msg)) { // Unregistration was successful - remove from this sessions // list of registrations if ($this->registrationsBySession->contains($session) && in_array($procedure, $this->registrationsBySession[$session])) { $registrationsInSession = $this->registrationsBySession[$session]; array_splice($registrationsInSession, array_search($procedure, $registrationsInSession), 1); } } return; } } // apparently we didn't find anything to unregister $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure')); }