Skip to content

Commit 6708680

Browse files
committed
Merge pull request #17 from jbaldwin/master
Added ClusterBuilder->withPort($port)
2 parents f9ba147 + 98f6ffa commit 6708680

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

ext/php_cassandra.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const zend_function_entry cassandra_functions[] = {
142142
PHP_FE(cassandra_cluster_set_token_aware_routing, NULL)
143143
PHP_FE(cassandra_cluster_set_credentials, NULL)
144144
PHP_FE(cassandra_cluster_set_contact_points, NULL)
145+
PHP_FE(cassandra_cluster_set_port, NULL)
145146
PHP_FE(cassandra_cluster_set_ssl, NULL)
146147
/* CassSsl */
147148
PHP_FE(cassandra_ssl_new, NULL)
@@ -671,6 +672,23 @@ PHP_FUNCTION(cassandra_cluster_set_contact_points)
671672
CHECK_RESULT(rc);
672673
}
673674

675+
PHP_FUNCTION(cassandra_cluster_set_port)
676+
{
677+
CassCluster* cluster;
678+
long port;
679+
zval* cluster_resource;
680+
681+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &port) == FAILURE) {
682+
RETURN_FALSE;
683+
}
684+
685+
ZEND_FETCH_RESOURCE(cluster, CassCluster*, &cluster_resource, -1,
686+
PHP_CASSANDRA_CLUSTER_RES_NAME, le_cassandra_cluster_res);
687+
688+
CassError rc = cass_cluster_set_port(cluster, (int)port);
689+
CHECK_RESULT(rc);
690+
}
691+
674692
PHP_FUNCTION(cassandra_cluster_set_ssl)
675693
{
676694
CassCluster* cluster;

ext/php_cassandra.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ PHP_FUNCTION(cassandra_cluster_set_load_balance_dc_aware);
126126
PHP_FUNCTION(cassandra_cluster_set_token_aware_routing);
127127
PHP_FUNCTION(cassandra_cluster_set_credentials);
128128
PHP_FUNCTION(cassandra_cluster_set_contact_points);
129+
PHP_FUNCTION(cassandra_cluster_set_port);
129130
PHP_FUNCTION(cassandra_cluster_set_ssl);
130131

131132
/* CassSsl */

src/Cassandra/Cluster/Builder.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ final class Builder
132132
*/
133133
private $defaultTimeout;
134134

135+
/**
136+
* Default port for connection.
137+
* Default: 9042
138+
*
139+
* @var int
140+
*/
141+
private $port;
142+
135143
/**
136144
* @access private
137145
*/
@@ -143,6 +151,7 @@ public function __construct()
143151
$this->defaultConsistency = \Cassandra::CONSISTENCY_ONE;
144152
$this->defaultPageSize = 10000;
145153
$this->defaultTimeout = null;
154+
$this->port = 9042;
146155
}
147156

148157
/**
@@ -190,6 +199,10 @@ public function build()
190199

191200
cassandra_cluster_set_contact_points($cluster, $this->contactPoints);
192201

202+
if (!is_null($this->port) && $this->port != 9042) {
203+
cassandra_cluster_set_port($cluster, $this->port);
204+
}
205+
193206
return new DefaultCluster($cluster, $options, $ssl);
194207
}
195208

@@ -287,6 +300,20 @@ public function withContactPoints($host)
287300
return $this;
288301
}
289302

303+
/**
304+
* Configures the port for endpoints.
305+
*
306+
* @param int $port an ip address string
307+
*
308+
* @return self
309+
*/
310+
public function withPort($port)
311+
{
312+
$this->port = $port;
313+
314+
return $this;
315+
}
316+
290317
/**
291318
* Configures this cluster to use a round robin load balancing policy.
292319
*

0 commit comments

Comments
 (0)