11<?php
2-
3- /**
4- * Connection Class.
5- *
6- * PHP version 5
7- *
8- * @category Class
9- *
10- * @author Raül Përez <repejota@gmail.com>
11- * @license http://opensource.org/licenses/MIT The MIT License (MIT)
12- *
13- * @link https://github.com/repejota/phpnats
14- */
15-
162namespace Nats ;
173
184/**
195 * Connection Class.
20- *
21- * @category Class
22- *
23- * @author Raül Përez <repejota@gmail.com>
24- * @license http://opensource.org/licenses/MIT The MIT License (MIT)
25- *
26- * @link https://github.com/repejota/phpnats
276 */
287class Connection
298{
@@ -105,6 +84,11 @@ public function getSubscriptions()
10584 return array_keys ($ this ->subscriptions );
10685 }
10786
87+ /**
88+ * Connection options object
89+ *
90+ * @var ConnectionOptions|null
91+ */
10892 private $ options = null ;
10993
11094 /**
@@ -117,8 +101,7 @@ public function getSubscriptions()
117101 /**
118102 * Constructor.
119103 *
120- * @param string $host name, by default "localhost"
121- * @param int $port number, by default 4222
104+ * @param ConnectionOptions $options Connection options object.
122105 */
123106 public function __construct (ConnectionOptions $ options = null )
124107 {
@@ -135,7 +118,8 @@ public function __construct(ConnectionOptions $options = null)
135118 /**
136119 * Sends data thought the stream.
137120 *
138- * @param string $payload message data
121+ * @param string $payload Message data.
122+ * @return void
139123 */
140124 private function send ($ payload )
141125 {
@@ -146,7 +130,7 @@ private function send($payload)
146130 /**
147131 * Receives a message thought the stream.
148132 *
149- * @param int $len Number of bytes to receive
133+ * @param integer $len Number of bytes to receive.
150134 *
151135 * @return string
152136 */
@@ -162,7 +146,7 @@ private function receive($len = null)
162146 /**
163147 * Returns an stream socket to the desired server.
164148 *
165- * @param string $address Server url string
149+ * @param string $address Server url string.
166150 *
167151 * @return resource
168152 */
@@ -179,7 +163,7 @@ private function getStream($address)
179163 /**
180164 * Checks if the client is connected to a server.
181165 *
182- * @return bool
166+ * @return boolean
183167 */
184168 public function isConnected ()
185169 {
@@ -188,6 +172,8 @@ public function isConnected()
188172
189173 /**
190174 * Connect to server.
175+ *
176+ * @return void
191177 */
192178 public function connect ()
193179 {
@@ -198,6 +184,8 @@ public function connect()
198184
199185 /**
200186 * Sends PING message.
187+ *
188+ * @return void
201189 */
202190 public function ping ()
203191 {
@@ -209,10 +197,9 @@ public function ping()
209197 /**
210198 * Publish publishes the data argument to the given subject.
211199 *
212- * @param string $subject message topic
213- * @param string $payload message data
214- *
215- * @return string
200+ * @param string $subject Message topic.
201+ * @param string $payload Message data.
202+ * @return void
216203 */
217204 public function publish ($ subject , $ payload )
218205 {
@@ -225,9 +212,8 @@ public function publish($subject, $payload)
225212 /**
226213 * Subscribes to an specific event given a subject.
227214 *
228- * @param string $subject message topic
229- * @param mixed $callback closure to be executed as callback
230- *
215+ * @param string $subject Message topic.
216+ * @param resource $callback Closure to be executed as callback.
231217 * @return string
232218 */
233219 public function subscribe ($ subject , $ callback )
@@ -243,7 +229,8 @@ public function subscribe($subject, $callback)
243229 /**
244230 * Unsubscribe from a event given a subject.
245231 *
246- * @param string $sid Subscription ID
232+ * @param string $sid Subscription ID.
233+ * @return void
247234 */
248235 public function unsubscribe ($ sid )
249236 {
@@ -253,6 +240,8 @@ public function unsubscribe($sid)
253240
254241 /**
255242 * Handles PING command.
243+ *
244+ * @return void
256245 */
257246 private function handlePING ()
258247 {
@@ -262,7 +251,7 @@ private function handlePING()
262251 /**
263252 * Handles MSG command.
264253 *
265- * @param string $line Message command from NATS
254+ * @param string $line Message command from NATS.
266255 *
267256 * @return \Exception|void
268257 */
@@ -287,9 +276,8 @@ private function handleMSG($line)
287276 /**
288277 * Waits for messages.
289278 *
290- * @param int $quantity Number of messages to wait for
291- *
292- * @return \Exception|void
279+ * @param integer $quantity Number of messages to wait for.
280+ * @return resource $connection Connection object
293281 */
294282 public function wait ($ quantity = 0 )
295283 {
@@ -307,7 +295,7 @@ public function wait($quantity = 0)
307295 $ count = $ count + 1 ;
308296 $ this ->handleMSG ($ line );
309297 if (($ quantity != 0 ) && ($ count >= $ quantity )) {
310- return ;
298+ return $ this ;
311299 }
312300 }
313301 }
@@ -318,6 +306,8 @@ public function wait($quantity = 0)
318306
319307 /**
320308 * Reconnects to the server.
309+ *
310+ * @return void
321311 */
322312 public function reconnect ()
323313 {
@@ -328,6 +318,8 @@ public function reconnect()
328318
329319 /**
330320 * Close will close the connection to the server.
321+ *
322+ * @return void
331323 */
332324 public function close ()
333325 {
0 commit comments