Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit c42c92e

Browse files
author
Raül Pérez
committed
bump 0.0.4
1 parent fcb5a4f commit c42c92e

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.3
1+
0.0.4

src/Connection.php

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/**
1616
* Connection Class
17-
*
17+
*
1818
* @category Class
1919
* @package Nats\Tests\Unit
2020
* @author Raül Përez <repejota@gmail.com>
@@ -26,7 +26,7 @@ class Connection
2626
/**
2727
* Version number
2828
*/
29-
const VERSION = "0.0.3";
29+
public $VERSION = "0.0.0";
3030

3131
/**
3232
* Number of PINGS
@@ -142,6 +142,8 @@ public function getSubscriptions()
142142
*/
143143
public function __construct($host = "localhost", $port = 4222)
144144
{
145+
$this->VERSION = file_get_contents("./VERSION");
146+
145147
$this->_pings = 0;
146148
$this->_pubs = 0;
147149
$this->_subscriptions = 0;
@@ -185,7 +187,7 @@ private function _receive($len = null)
185187
* Returns an stream socket to the desired server.
186188
*
187189
* @param string $address Server url string
188-
*
190+
*
189191
* @return resource
190192
*/
191193
private function _getStream($address)
@@ -203,7 +205,7 @@ private function _getStream($address)
203205
*
204206
* @return bool
205207
*/
206-
public function isConnected()
208+
public function isConnected()
207209
{
208210
return isset($this->_streamSocket);
209211
}
@@ -221,14 +223,40 @@ public function isConnected()
221223
* Example:
222224
* nats://user:pass@localhost:4222
223225
*
226+
* @param null $host host name to connect
227+
* @param null $port host port to connect
228+
* @param bool $verbose if verbose mode is enabled
229+
* @param bool $pedantic if pedantic mode is enabled
230+
* @param bool $reconnect if reconnect mode is enabled
231+
*
224232
* @return void
225233
*/
226-
public function connect()
227-
{
228-
$options = '{ "verbose": false, "pedantic": false, "reconnect": true }';
234+
public function connect($host = null,
235+
$port = null,
236+
$verbose = false,
237+
$pedantic = false,
238+
$reconnect = true
239+
) {
240+
if (isset($host)) {
241+
$this->_host = $host;
242+
$this->_address = "tcp://" . $this->_host . ":" . $this->_port;
243+
}
244+
if (isset($port)) {
245+
$this->_port = $port;
246+
$this->_address = "tcp://" . $this->_host . ":" . $this->_port;
247+
}
248+
$verbose = ($verbose) ? 'true' : 'false';
249+
$pedantic = ($pedantic) ? 'true' : 'false';
250+
$reconnect = ($reconnect) ? 'true' : 'false';
251+
252+
$options = '{ ';
253+
$options .= ' "verbose": ' . $verbose . ', ';
254+
$options .= ' "pedantic": ' . $pedantic . ', ';
255+
$options .= ' "reconnect": ' . $reconnect;
256+
$options .= ' }';
229257

230258
$this->_streamSocket = $this->_getStream($this->_address);
231-
$msg = 'CONNECT '. $options;
259+
$msg = 'CONNECT ' . $options;
232260
$this->_send($msg);
233261
}
234262

@@ -295,7 +323,8 @@ public function unsubscribe($sid)
295323
*
296324
* @return void
297325
*/
298-
private function _handlePING() {
326+
private function _handlePING()
327+
{
299328
$this->_send("PONG");
300329
}
301330

@@ -306,7 +335,8 @@ private function _handlePING() {
306335
*
307336
* @return \Exception|void
308337
*/
309-
private function _handleMSG($line) {
338+
private function _handleMSG($line)
339+
{
310340
$parts = explode(" ", $line);
311341
$length = $parts[3];
312342
$sid = $parts[2];
@@ -325,7 +355,7 @@ private function _handleMSG($line) {
325355
* Waits for messages
326356
*
327357
* @param int $quantity Number of messages to wait for
328-
*
358+
*
329359
* @return \Exception|void
330360
*/
331361
public function wait($quantity = 0)

0 commit comments

Comments
 (0)