Thruway\Procedure::processRegister PHP Метод

processRegister() публичный Метод

Process register
public processRegister ( Session $session, Thruway\Message\RegisterMessage $msg ) : boolean
$session Session
$msg Thruway\Message\RegisterMessage
Результат boolean
    public function processRegister(Session $session, RegisterMessage $msg)
    {
        $registration = Registration::createRegistrationFromRegisterMessage($session, $msg);
        if (count($this->registrations) > 0) {
            // we already have something registered
            if ($this->getAllowMultipleRegistrations()) {
                return $this->addRegistration($registration, $msg);
            } else {
                // we are not allowed multiple registrations, but we may want
                // to replace an orphaned session
                $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.procedure_already_exists');
                $options = $msg->getOptions();
                // get the existing registration
                /** @var Registration $oldRegistration */
                $oldRegistration = $this->registrations[0];
                if (isset($options->replace_orphaned_session) && $options->replace_orphaned_session == "yes") {
                    try {
                        $oldRegistration->getSession()->ping(5)->then(function ($res) use($session, $errorMsg) {
                            // the ping came back - send procedure_already_exists
                            $session->sendMessage($errorMsg);
                        }, function ($r) use($oldRegistration, $session, $registration, $msg) {
                            // bring down the exiting session because the
                            // ping timed out
                            $deadSession = $oldRegistration->getSession();
                            // this should do all the cleanup needed and remove the
                            // registration from this procedure also
                            $deadSession->shutdown();
                            // complete this registration now
                            return $this->addRegistration($registration, $msg);
                        });
                    } catch (\Exception $e) {
                        $session->sendMessage($errorMsg);
                    }
                } else {
                    $session->sendMessage($errorMsg);
                }
            }
        } else {
            // this is the first registration
            // setup the procedure to match the options
            $this->setDiscloseCaller($registration->getDiscloseCaller());
            $this->setAllowMultipleRegistrations($registration->getAllowMultipleRegistrations());
            $this->setInvokeType($registration->getInvokeType());
            return $this->addRegistration($registration, $msg);
        }
    }

Usage Example

Пример #1
0
 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()));
 }
All Usage Examples Of Thruway\Procedure::processRegister