WAMP->prefixes[$curie] = $uri; if ($from_server) { $prefix = new Prefix($conn); $prefix->setPrefix($curie, $uri); $this->_msg_buffer->enqueue($prefix); } } public function onOpen(ConnectionInterface $conn) { $conn->WAMP = new \StdClass; $conn->WAMP->prefixes = array(); $conn->WAMP->subscriptions = array(); $wamp = $this; $conn->WAMP->addPrefix = function($curie, $uri) use ($wamp, $conn) { $wamp->addPrefix($conn, $curie, $uri, true); }; return $this->_decorating->onOpen($conn); } /** * @{inherit} * @throws Exception * @throws JSONException */ public function onMessage(ConnectionInterface $from, $msg) { if (null === ($json = @json_decode($msg, true))) { throw new JSONException; } switch ($json[0]) { case static::MSG_PREFIX: $ret = $this->addPrefix($from, $json[1], $json[2]); break; case static::MSG_CALL: array_shift($json); $callID = array_shift($json); $procURI = array_shift($json); if (count($json) == 1 && is_array($json[0])) { $json = $json[0]; } $ret = $this->_decorating->onCall($from, $callID, $procURI, $json); break; case static::MSG_SUBSCRIBE: $ret = $this->_decorating->onSubscribe($from, $this->getUri($from, $json[1])); break; case static::MSG_UNSUBSCRIBE: $ret = $this->_decorating->onUnSubscribe($from, $this->getUri($from, $json[1])); break; case static::MSG_PUBLISH: $ret = $this->_decorating->onPublish($from, $this->getUri($from, $json[1]), $json[2]); break; default: throw new Exception('Invalid message type'); } return $this->attachStack($ret); } /** * Get the full request URI from the connection object if a prefix has been established for it * @param Ratchet\Resource\Connection * @param ... * @return string */ protected function getUri(ConnectionInterface $conn, $uri) { return (isset($conn->WAMP->prefixes[$uri]) ? $conn->WAMP->prefixes[$uri] : $uri); } /** * If the developer's application as set some server-to-client prefixes to be set, * this method ensures those are taxied to the next outgoing message * @param Ratchet\Resource\Command\CommandInterface|NULL * @return Ratchet\Resource\Command\Composite */ protected function attachStack(CommandInterface $command = null) { $stack = $this->_msg_buffer; $stack->enqueue($command); $this->_msg_buffer = new Composite; return $stack; } public function __construct(WAMPServerComponentInterface $server_component) { $this->_decorating = $server_component; $this->_msg_buffer = new Composite; } public function onClose(ConnectionInterface $conn) { return $this->_decorating->onClose($conn); } public function onError(ConnectionInterface $conn, \Exception $e) { return $this->_decorating->onError($conn, $e); } }