示例#1
0
 /**
  * Process result as an array
  *
  * @param mixed $results
  * @param \Thruway\Message\InvocationMessage $msg
  * @param \Thruway\ClientSession $session
  */
 private function processResultAsArray($results, InvocationMessage $msg, ClientSession $session)
 {
     $options = new \stdClass();
     if ($results instanceof Result) {
         $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $results->getArguments(), $results->getArgumentsKw());
     } else {
         $results = is_array($results) ? $results : [$results];
         $results = !$this::is_list($results) ? [$results] : $results;
         $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $results);
     }
     $session->sendMessage($yieldMsg);
 }
示例#2
0
文件: Call.php 项目: binaek89/Thruway
 /**
  * Get InvocationMessage
  *
  * @throws \Exception
  * @return \Thruway\Message\InvocationMessage
  */
 public function getInvocationMessage()
 {
     if ($this->invocationMessage === null) {
         // try to create one
         if ($this->registration === null) {
             throw new \Exception("You must set the registration prior to calling getInvocationMessage");
         }
         if ($this->callMessage === null) {
             throw new \Exception("You must set the CallMessage prior to calling getInvocationMessage");
         }
         $invocationMessage = InvocationMessage::createMessageFrom($this->getCallMessage(), $this->getRegistration());
         $invocationMessage->setRequestId($this->getInvocationRequestId());
         $details = [];
         if ($this->getRegistration()->getDiscloseCaller() === true && $this->getCallerSession()->getAuthenticationDetails()) {
             $authenticationDetails = $this->getCallerSession()->getAuthenticationDetails();
             $details = ["caller" => $this->getCallerSession()->getSessionId(), "authid" => $authenticationDetails->getAuthId(), "authrole" => $authenticationDetails->getAuthRole(), "authroles" => $authenticationDetails->getAuthRoles(), "authmethod" => $authenticationDetails->getAuthMethod()];
             if ($authenticationDetails->getAuthExtra() !== null) {
                 $details["_thruway_authextra"] = $authenticationDetails->getAuthExtra();
             }
         }
         // TODO: check to see if callee supports progressive call
         $callOptions = $this->getCallMessage()->getOptions();
         $isProgressive = false;
         if (is_object($callOptions) && isset($callOptions->receive_progress) && $callOptions->receive_progress) {
             $details = array_merge($details, ["receive_progress" => true]);
             $isProgressive = true;
         }
         // if nothing was added to details - change ot stdClass so it will serialize correctly
         if (count($details) == 0) {
             $details = new \stdClass();
         }
         $invocationMessage->setDetails($details);
         $this->setIsProgressive($isProgressive);
         $this->setInvocationMessage($invocationMessage);
     }
     return $this->invocationMessage;
 }
示例#3
0
 /**
  * @param Session $session
  * @param CallMessage $msg
  * @return bool
  */
 private function processCall(Session $session, CallMessage $msg)
 {
     $registration = $this->getRegistrationByProcedureName($msg->getProcedureName());
     if (!$registration) {
         $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
         $this->manager->error('No registration for call message: ' . $msg->getProcedureName());
         $errorMsg->setErrorURI('wamp.error.no_such_registration');
         $session->sendMessage($errorMsg);
         return false;
     }
     $invocationMessage = InvocationMessage::createMessageFrom($msg, $registration);
     if ($registration->getDiscloseCaller() === true && $session->getAuthenticationDetails()) {
         $details = ["caller" => $session->getSessionId(), "authid" => $session->getAuthenticationDetails()->getAuthId(), "authmethod" => $session->getAuthenticationDetails()->getAuthMethod()];
         $invocationMessage->setDetails($details);
     }
     $call = new Call($msg, $session, $invocationMessage, $registration->getSession());
     $this->calls->attach($call);
     $registration->getSession()->sendMessage($invocationMessage);
 }
示例#4
0
 /**
  * @param ClientSession $session
  * @param InvocationMessage $msg
  */
 public function processInvocation(ClientSession $session, InvocationMessage $msg)
 {
     foreach ($this->registrations as $key => $registration) {
         if (!isset($registration["registration_id"])) {
             $this->logger->info("Registration_id not set for " . $registration['procedure_name'] . "\n");
         } else {
             if ($registration["registration_id"] === $msg->getRegistrationId()) {
                 if ($registration['callback'] === null) {
                     // this is where calls end up if the client has called unregister but
                     // have not yet received confirmation from the router about the
                     // unregistration
                     $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, "thruway.error.unregistering"));
                     return;
                 }
                 $results = $registration["callback"]($msg->getArguments(), $msg->getArgumentsKw(), $msg->getDetails());
                 if ($results instanceof Promise) {
                     // the result is a promise - hook up stuff as a callback
                     $results->then(function ($promiseResults) use($msg, $session) {
                         $promiseResults = is_array($promiseResults) ? $promiseResults : [$promiseResults];
                         $promiseResults = !$this::is_list($promiseResults) ? [$promiseResults] : $promiseResults;
                         $options = new \stdClass();
                         $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $promiseResults);
                         $session->sendMessage($yieldMsg);
                     }, function ($errorUri = null, $errorArgs = null, $errorArgsKw = null) use($msg, $session, $registration) {
                         $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
                         if ($errorUri !== null) {
                             $errorMsg->setErrorURI($registration['procedure_name'] . '.error');
                         } else {
                             $errorMsg->setErrorURI("thruway.invocation.error");
                         }
                         if (is_array($errorArgs)) {
                             $errorMsg->setArguments($errorArgs);
                         }
                         if (is_array($errorArgsKw)) {
                             $errorMsg->setArgumentsKw($errorArgsKw);
                         }
                         $session->sendMessage($errorMsg);
                     });
                 } else {
                     $results = !$this::is_list($results) ? [$results] : $results;
                     $options = new \stdClass();
                     $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $results);
                     $session->sendMessage($yieldMsg);
                 }
                 break;
             }
         }
     }
 }