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)); }
/** * 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; }
/** * 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); } }