예제 #1
0
파일: Callee.php 프로젝트: pacho104/redbpim
 /**
  * Process InvocationMessage
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Message\InvocationMessage $msg
  */
 protected function processInvocation(ClientSession $session, InvocationMessage $msg)
 {
     foreach ($this->registrations as $key => $registration) {
         if (!isset($registration["registration_id"])) {
             Logger::info($this, "Registration_id not set for " . $registration['procedure_name']);
         } 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));
                     return;
                 }
                 try {
                     $results = $registration["callback"]($msg->getArguments(), $msg->getArgumentsKw(), $msg->getDetails());
                     if ($results instanceof Promise) {
                         $this->processResultAsPromise($results, $msg, $session, $registration);
                     } else {
                         $this->processResultAsArray($results, $msg, $session);
                     }
                 } catch (\Exception $e) {
                     $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
                     $errorMsg->setErrorURI($registration['procedure_name'] . '.error');
                     $errorMsg->setArguments([$e->getMessage()]);
                     $errorMsg->setArgumentsKw($e);
                     $session->sendMessage($errorMsg);
                 }
                 break;
             }
         }
     }
 }
예제 #2
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;
             }
         }
     }
 }