예제 #1
0
 /**
  * submit a message to the message bus that has to be sent to a client.
  *
  * @param string $command
  * @param string $body
  * @param string $value
  * @param string|null $sessionid
  * @return bool
  * @throws \Thallium\Controllers\ExceptionController if an error occurs.
  */
 public function sendMessageToClient($command, $body, $value, $sessionid = null)
 {
     if ($this->isSuppressOutboundMessaging()) {
         return true;
     }
     if (!isset($command) || empty($command) || !is_string($command)) {
         static::raiseError(__METHOD__ . '(), $command parameter is invalid!');
         return false;
     }
     if (!isset($body) || empty($body) || !is_string($body)) {
         static::raiseError(__METHOD__ . '(), $body parameter is invalid!');
         return false;
     }
     if (isset($value) && !empty($value) && !is_string($value)) {
         static::raiseError(__METHOD__ . '(), $value parameter is invalid!');
         return false;
     }
     if (empty($sessionid) && ($sessionid = $this->getSessionIdFromJob()) === false) {
         static::raiseError(__CLASS__ . '::getSessionIdFromJob() returned false!');
         return false;
     }
     if (!isset($sessionid) || empty($sessionid) || !is_string($sessionid)) {
         static::raiseError(__METHOD__ . '(), the specified $sessionid is invalid!');
         return false;
     }
     try {
         $msg = new \Thallium\Models\MessageModel();
     } catch (\Exception $e) {
         static::raiseError(__METHOD__ . '(), failed to load MessageModel!', false, $e);
         return false;
     }
     if (!$msg->setCommand($command)) {
         static::raiseError(get_class($msg) . '::setCommand() returned false!');
         return false;
     }
     if (!$msg->setBody($body)) {
         static::raiseError(get_class($msg) . '::setBody() returned false!');
         return false;
     }
     if (!$msg->setValue($value)) {
         static::raiseError(get_class($msg) . '::setValue() returned false!');
         return false;
     }
     if (!$msg->setSessionId($sessionid)) {
         static::raiseError(get_class($msg) . '::setSessionId() returned false!');
         return false;
     }
     if (!$msg->setScope('outbound')) {
         static::raiseError(get_class($msg) . '::setScope() returned false!');
         return false;
     }
     if (!$msg->save()) {
         static::raiseError(get_class($msg) . '::save() returned false!');
         return false;
     }
     return true;
 }
예제 #2
0
 public function sendMessageToClient($command, $body, $value, $sessionid = null)
 {
     global $jobs;
     if ($this->isSuppressOutboundMessaging()) {
         return true;
     }
     if (!isset($command) || empty($command) || !is_string($command)) {
         static::raiseError(__METHOD__ . ', parameter $command is mandatory and has to be a string!');
         return false;
     }
     if (!isset($body) || empty($body) || !is_string($body)) {
         static::raiseError(__METHOD__ . ', parameter $body is mandatory and has to be a string!');
         return false;
     }
     if (isset($value) && !empty($value) && !is_string($value)) {
         static::raiseError(__METHOD__ . ', parameter $value has to be a string!');
         return false;
     }
     if (empty($sessionid) && !($sessionid = $this->getSessionIdFromJob())) {
         static::raiseError(__METHOD__ . ', no session id returnd by getSessionIdFromJob()!');
         return false;
     }
     if (!isset($sessionid) || empty($sessionid) || !is_string($sessionid)) {
         static::raiseError(__METHOD__ . ', the specified $sessionid is invalid!');
         return false;
     }
     try {
         $msg = new \Thallium\Models\MessageModel();
     } catch (\Exception $e) {
         static::raiseError(__METHOD__ . ', failed to load MessageModel!');
         return false;
     }
     if (!$msg->setCommand($command)) {
         static::raiseError(get_class($msg) . '::setCommand() returned false!');
         return false;
     }
     if (!$msg->setBody($body)) {
         static::raiseError(get_class($msg) . '::setBody() returned false!');
         return false;
     }
     if (!$msg->setValue($value)) {
         static::raiseError(get_class($msg) . '::setValue() returned false!');
         return false;
     }
     if (!$msg->setSessionId($sessionid)) {
         static::raiseError(get_class($msg) . '::setSessionId() returned false!');
         return false;
     }
     if (!$msg->setScope('outbound')) {
         static::raiseError(get_class($msg) . '::setScope() returned false!');
         return false;
     }
     if (!$msg->save()) {
         static::raiseError(get_class($msg) . '::save() returned false!');
         return false;
     }
     return true;
 }