Ejemplo n.º 1
0
 /**
  * Process publish message
  *
  * @param \Thruway\Session $session
  * @param \Thruway\Message\PublishMessage $msg
  */
 protected function processPublish(Session $session, PublishMessage $msg)
 {
     Logger::debug($this, "processing publish message");
     $includePublisher = false;
     $excludedSessions = [];
     $whiteList = null;
     $options = $msg->getOptions();
     if (is_array($options)) {
         // see if they wanted confirmation
         if (isset($options['acknowledge']) && $options['acknowledge'] == true) {
             $publicationId = Session::getUniqueId();
             $session->sendMessage(new PublishedMessage($msg->getRequestId(), $publicationId));
         }
         if (isset($options['exclude_me']) && !$options['exclude_me']) {
             $includePublisher = true;
         }
         if (isset($options['exclude']) && is_array($options['exclude'])) {
             // fixup exclude array - make sure it is legit
             foreach ($options['exclude'] as $excludedSession) {
                 if (is_numeric($excludedSession)) {
                     array_push($excludedSessions, $excludedSession);
                 }
             }
         }
         if (isset($options['eligible']) && is_array($options['eligible'])) {
             $whiteList = [];
             foreach ($options['eligible'] as $sessionId) {
                 if (is_numeric($sessionId)) {
                     array_push($whiteList, $sessionId);
                 }
             }
         }
     }
     /* @var $subscription \Thruway\Subscription */
     foreach ($this->subscriptions as $subscription) {
         if ($msg->getTopicName() == $subscription->getTopic() && ($includePublisher || $subscription->getSession() != $session)) {
             if (!in_array($subscription->getSession()->getSessionId(), $excludedSessions)) {
                 if ($whiteList === null || in_array($subscription->getSession()->getSessionId(), $whiteList)) {
                     $eventMsg = EventMessage::createFromPublishMessage($msg, $subscription->getId());
                     $this->disclosePublisherOption($session, $eventMsg, $subscription);
                     $subscription->getSession()->sendMessage($eventMsg);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Session $session
  * @param PublishMessage $msg
  */
 public function processPublish(Session $session, PublishMessage $msg)
 {
     $this->manager->debug("processing publish message");
     $receivers = isset($this->topics[$msg->getTopicName()]) ? $this->topics[$msg->getTopicName()] : null;
     //If the topic doesn't have any subscribers
     if (empty($receivers)) {
         $receivers = array();
     }
     // see if they wanted confirmation
     $options = $msg->getOptions();
     if (is_array($options)) {
         if (isset($options['acknowledge']) && $options['acknowledge'] == true) {
             $publicationId = Session::getUniqueId();
             $session->sendMessage(new PublishedMessage($msg->getRequestId(), $publicationId));
         }
     }
     $eventMsg = EventMessage::createFromPublishMessage($msg);
     /* @var $receiver Session */
     foreach ($receivers as $receiver) {
         if ($receiver != $session) {
             $receiver->sendMessage($eventMsg);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Send an Event Message for each subscription
  * @param Session $session
  * @param PublishMessage $msg
  * @param Subscription $subscription
  */
 private function sendEventMessage(Session $session, PublishMessage $msg, Subscription $subscription)
 {
     $sessionId = $subscription->getSession()->getSessionId();
     $authroles = [];
     $authid = "";
     $authenticationDetails = $subscription->getSession()->getAuthenticationDetails();
     if ($authenticationDetails) {
         $authroles = $authenticationDetails->getAuthRoles();
         $authid = $authenticationDetails->getAuthId();
     }
     if ((!$msg->excludeMe() || $subscription->getSession() != $session) && !$msg->isExcluded($sessionId) && $msg->isWhiteListed($sessionId) && $msg->hasEligibleAuthrole($authroles) && $msg->hasEligibleAuthid($authid)) {
         $eventMsg = EventMessage::createFromPublishMessage($msg, $subscription->getId());
         if ($subscription->isDisclosePublisher() === true) {
             $eventMsg->disclosePublisher($session);
         }
         if ($this->getMatchType() != "exact") {
             $eventMsg->getDetails()->topic = $msg->getUri();
         }
         $subscription->sendEventMessage($eventMsg);
     }
 }
Ejemplo n.º 4
0
 /**
  * Process publish message
  *
  * @param \Thruway\Session $session
  * @param \Thruway\Message\PublishMessage $msg
  */
 protected function processPublish(Session $session, PublishMessage $msg)
 {
     if ($msg->getPublicationId() === null) {
         $msg->setPublicationId(Utils::getUniqueId());
     }
     /** @var SubscriptionGroup $subscriptionGroup */
     foreach ($this->subscriptionGroups as $subscriptionGroup) {
         $subscriptionGroup->processPublish($session, $msg);
     }
     if ($msg->acknowledge()) {
         $session->sendMessage(new PublishedMessage($msg->getRequestId(), $msg->getPublicationId()));
     }
 }
Ejemplo n.º 5
0
 /**
  * Create event message from publish message
  *
  * @param \Thruway\Message\PublishMessage $msg
  * @param int $subscriptionId
  * @return \Thruway\Message\EventMessage
  */
 public static function createFromPublishMessage(PublishMessage $msg, $subscriptionId)
 {
     return new static($subscriptionId, $msg->getPublicationId(), new \stdClass(), $msg->getArguments(), $msg->getArgumentsKw(), $msg->getTopicName());
 }