diff --git a/src/Ratchet/Component/WAMP/Command/Action/CallError.php b/src/Ratchet/Component/WAMP/Command/Action/CallError.php index ad28763..373e1fa 100644 --- a/src/Ratchet/Component/WAMP/Command/Action/CallError.php +++ b/src/Ratchet/Component/WAMP/Command/Action/CallError.php @@ -3,30 +3,76 @@ namespace Ratchet\Component\WAMP\Command\Action; use Ratchet\Resource\Command\Action\SendMessage; use Ratchet\Component\WAMP\WAMPServerComponent as WAMP; +/** + * Respond to a client RPC with an error + */ class CallError extends SendMessage { + /** + * @var string + */ protected $_id; + /** + * @var string + */ protected $_uri; - protected $_desc; + /** + * @var string + */ + protected $_desc = ''; - public function setError($callId, $uri, $desc) { + /** + * @var string + */ + protected $_details; + + /** + * @param string The unique ID given by the client to respond to + * @param string The URI given by the client ot respond to + * @param string A developer-oriented description of the error + * @param string|null An optional human readable detail message to send back + * @return CallError + */ + public function setError($callId, $uri, $desc = '', $details = null) { $this->_id = $callId; $this->_uri = $uri; $this->_desc = $desc; - return $this->setMessage(json_encode(array(WAMP::MSG_CALL_ERROR, $callId, $uri, $desc))); + $data = array(WAMP::MSG_CALL_ERROR, $callId, $uri, $desc); + + if (null !== $details) { + $data[] = $details; + } + + return $this->setMessage(json_encode($data)); } + /** + * @return string|null + */ public function getId() { return $this->_id; } + /** + * @return string|null + */ public function getUri() { return $this->_uri; } + /** + * @return string + */ public function getDescription() { return $this->_desc; } + + /** + * @return string|null + */ + public function getDetails() { + return $this->_details; + } } \ No newline at end of file diff --git a/src/Ratchet/Component/WAMP/Command/Action/CallResult.php b/src/Ratchet/Component/WAMP/Command/Action/CallResult.php index 4df370d..b65d062 100644 --- a/src/Ratchet/Component/WAMP/Command/Action/CallResult.php +++ b/src/Ratchet/Component/WAMP/Command/Action/CallResult.php @@ -4,12 +4,24 @@ use Ratchet\Resource\Command\Action\SendMessage; use Ratchet\Component\WAMP\WAMPServerComponent as WAMP; /** + * Respond to a client RPC */ class CallResult extends SendMessage { + /** + * @var string + */ protected $_id; + /** + * @var array + */ protected $_data; + /** + * @param string The unique ID given by the client to respond to + * @param array An array of data to return to the client + * @return CallResult + */ public function setResult($callId, array $data = array()) { $this->_id = $callId; $this->_data = $data; @@ -17,10 +29,16 @@ class CallResult extends SendMessage { return $this->setMessage(json_encode(array(WAMP::MSG_CALL_RESULT, $callId, $data))); } + /** + * @return string|null + */ public function getId() { return $this->_id; } + /** + * @return array|null + */ public function getData() { return $this->_data; } diff --git a/src/Ratchet/Component/WAMP/Command/Action/Event.php b/src/Ratchet/Component/WAMP/Command/Action/Event.php index b711b74..9bf2e90 100644 --- a/src/Ratchet/Component/WAMP/Command/Action/Event.php +++ b/src/Ratchet/Component/WAMP/Command/Action/Event.php @@ -14,6 +14,6 @@ class Event extends SendMessage { * @return Event */ public function setEvent($uri, $msg) { - return $this->setMessage(json_encode(array(WAMP::MSG_EVENT, $uri, (string)$msg))); + return $this->setMessage(json_encode(array(WAMP::MSG_EVENT, $uri, $msg))); } } \ No newline at end of file diff --git a/src/Ratchet/Component/WAMP/WAMPServerComponent.php b/src/Ratchet/Component/WAMP/WAMPServerComponent.php index c60f6c3..6e3e353 100644 --- a/src/Ratchet/Component/WAMP/WAMPServerComponent.php +++ b/src/Ratchet/Component/WAMP/WAMPServerComponent.php @@ -84,7 +84,6 @@ class WAMPServerComponent implements WebSocketComponentInterface { $conn->WAMP = new \StdClass; $conn->WAMP->sessionId = uniqid(); $conn->WAMP->prefixes = array(); - $conn->WAMP->subscriptions = array(); $wamp = $this; $conn->WAMP->addPrefix = function($curie, $uri) use ($wamp, $conn) { diff --git a/tests/Ratchet/Tests/Mock/WAMPComponent.php b/tests/Ratchet/Tests/Mock/WAMPComponent.php new file mode 100644 index 0000000..9473e85 --- /dev/null +++ b/tests/Ratchet/Tests/Mock/WAMPComponent.php @@ -0,0 +1,36 @@ +last[__FUNCTION__] = func_get_args(); + } + + public function onSubscribe(ConnectionInterface $conn, $uri) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onUnSubscribe(ConnectionInterface $conn, $uri) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onPublish(ConnectionInterface $conn, $uri, $event) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onOpen(ConnectionInterface $conn) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onClose(ConnectionInterface $conn) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onError(ConnectionInterface $conn, \Exception $e) { + $this->last[__FUNCTION__] = func_get_args(); + } +} \ No newline at end of file