public function testStdClassOptions()
 {
     $options = new \stdClass();
     $options->match = "prefix";
     $msg = new SubscribeMessage(12345, $options, 'com.test.subscribe');
     $this->assertTrue(is_object($msg->getOptions()));
     $expectedJson = '[32,12345,{"match":"prefix"},"com.test.subscribe"]';
     $this->assertEquals($expectedJson, json_encode($msg));
 }
Example #2
0
 /**
  * Create Subscription from SubscribeMessage
  *
  * @param Session $session
  * @param SubscribeMessage $msg
  * @return Subscription
  */
 public static function createSubscriptionFromSubscribeMessage(Session $session, SubscribeMessage $msg)
 {
     $options = $msg->getOptions();
     $subscription = new Subscription($msg->getTopicName(), $session, $options);
     if (isset($options->disclose_publisher) && $options->disclose_publisher === true) {
         $subscription->setDisclosePublisher(true);
     }
     return $subscription;
 }
Example #3
0
 /**
  * @param $args
  * @throws \Exception
  */
 public function addStateHandler($args)
 {
     $uri = isset($args[0]->uri) ? $args[0]->uri : null;
     $handlerUri = isset($args[0]->handler_uri) ? $args[0]->handler_uri : null;
     $options = isset($args[0]->options) && is_object($args[0]->options) ? $args[0]->options : new \stdClass();
     $matchType = SubscribeMessage::getMatchTypeFromOption($options);
     $matcher = $this->broker->getMatcherForMatchType($matchType);
     if ($uri === null) {
         throw new \Exception("No uri set for state handler registration.");
     }
     if ($handlerUri === null) {
         throw new \Exception("No handler uri set for state handler registration.");
     }
     if ($matcher === false) {
         throw new \Exception("State handler match type \"" . $matchType . "\" is not registered.");
     }
     $stateHandlerRegistration = new StateHandlerRegistration($this->getSession(), $handlerUri, $uri, $options, $matcher);
     $this->stateHandlerRegistrations[] = $stateHandlerRegistration;
     $this->mapNewStateHandlerRegistration($stateHandlerRegistration);
 }
Example #4
0
 /**
  * @param Session $session
  * @param SubscribeMessage $msg
  */
 public function processSubscribe(Session $session, SubscribeMessage $msg)
 {
     if (!isset($this->topics[$msg->getTopicName()])) {
         $this->topics[$msg->getTopicName()] = array();
     }
     array_push($this->topics[$msg->getTopicName()], $session);
     //Check if this session has not already subscribed for this topic
     $subscriptionCheck = $this->checkSubscriptions($session->getSessionId(), $msg->getTopicName());
     if (!$subscriptionCheck) {
         $subscription = new Subscription($msg->getTopicName(), $session);
         $this->subscriptions->attach($subscription);
         $subscribedMsg = new SubscribedMessage($msg->getRequestId(), $msg->getTopicName());
         $session->sendMessage($subscribedMsg);
     }
 }
Example #5
0
 /**
  * Process subscribe message
  *
  * @param \Thruway\Session $session
  * @param \Thruway\Message\SubscribeMessage $msg
  */
 protected function processSubscribe(Session $session, SubscribeMessage $msg)
 {
     if (!static::uriIsValid($msg->getTopicName())) {
         $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
         $session->sendMessage($errorMsg->setErrorURI('wamp.error.invalid_uri'));
         return;
     }
     if (!isset($this->topics[$msg->getTopicName()])) {
         $this->topics[$msg->getTopicName()] = [];
     }
     array_push($this->topics[$msg->getTopicName()], $session);
     $subscription = Subscription::createSubscriptionFromSubscribeMessage($session, $msg);
     $this->subscriptions->attach($subscription);
     $subscribedMsg = new SubscribedMessage($msg->getRequestId(), $subscription->getId());
     $session->sendMessage($subscribedMsg);
 }
Example #6
0
 /**
  * Process subscribe message
  *
  * @param \Thruway\Session $session
  * @param \Thruway\Message\SubscribeMessage $msg
  * @throws \Exception
  */
 protected function processSubscribe(Session $session, SubscribeMessage $msg)
 {
     // get a subscription group "hash"
     /** @var MatcherInterface $matcher */
     $matcher = $this->getMatcherForMatchType($msg->getMatchType());
     if ($matcher === null) {
         Logger::alert($this, "no matching match type for \"" . $msg->getMatchType() . "\" for URI \"" . $msg->getUri() . "\"");
         return;
     }
     if (!$matcher->uriIsValid($msg->getUri(), $msg->getOptions())) {
         $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
         $session->sendMessage($errorMsg->setErrorURI('wamp.error.invalid_uri'));
         return;
     }
     $matchHash = $matcher->getMatchHash($msg->getUri(), $msg->getOptions());
     if (!isset($this->subscriptionGroups[$matchHash])) {
         $this->subscriptionGroups[$matchHash] = new SubscriptionGroup($matcher, $msg->getUri(), $msg->getOptions());
     }
     /** @var SubscriptionGroup $subscriptionGroup */
     $subscriptionGroup = $this->subscriptionGroups[$matchHash];
     $subscription = $subscriptionGroup->processSubscribe($session, $msg);
     $registry = $this->getStateHandlerRegistry();
     if ($registry !== null) {
         $registry->processSubscriptionAdded($subscription);
     }
 }
 /**
  * @return string
  */
 public function getMatchType()
 {
     return SubscribeMessage::getMatchTypeFromOption($this->getOptions());
 }