Skip to content

Commit 9c21bed

Browse files
committed
Update namespaces for used Thrift classes
1 parent f0deb5c commit 9c21bed

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

lib/phpcassa/Connection/ConnectionPool.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace phpcassa\Connection;
33

4+
use Thrift\Exception\TException;
5+
use Thrift\Exception\TTransportException;
6+
47
use phpcassa\Connection\ConnectionWrapper;
58
use phpcassa\Connection\MaxRetriesException;
69
use phpcassa\Connection\NoServerAvailable;
@@ -126,7 +129,7 @@ protected function make_conn() {
126129
array_push($this->queue, $new_conn);
127130
$this->stats['created'] += 1;
128131
return;
129-
} catch (\TException $e) {
132+
} catch (TException $e) {
130133
$h = $this->servers[$this->list_position];
131134
$err = $e;
132135
$msg = $e->getMessage();
@@ -270,7 +273,7 @@ public function call() {
270273
} catch (UnavailableException $ue) {
271274
$last_err = $ue;
272275
$this->handle_conn_failure($conn, $f, $ue, $retry_count);
273-
} catch (\TTransportException $tte) {
276+
} catch (TTransportException $tte) {
274277
$last_err = $tte;
275278
$this->handle_conn_failure($conn, $f, $tte, $retry_count);
276279
} catch (\Exception $e) {

lib/phpcassa/Connection/ConnectionWrapper.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22
namespace phpcassa\Connection;
33

4-
// These don't use namespaces yet, so we can't rely on the autoloader
5-
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
6-
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
7-
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';
8-
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
4+
use Thrift\Transport\TSocket;
5+
use Thrift\Transport\TFramedTransport;
6+
use Thrift\Transport\TBufferedTransport;
7+
use Thrift\Protocol\TBinaryProtocolAccelerated;
98

109
use cassandra\CassandraClient;
1110
use cassandra\AuthenticationRequest;
@@ -36,18 +35,18 @@ public function __construct($keyspace,
3635
$port = (int)$server[1];
3736
else
3837
$port = self::DEFAULT_PORT;
39-
$socket = new \TSocket($host, $port);
38+
$socket = new TSocket($host, $port);
4039

4140
if($send_timeout) $socket->setSendTimeout($send_timeout);
4241
if($recv_timeout) $socket->setRecvTimeout($recv_timeout);
4342

4443
if($framed_transport) {
45-
$transport = new \TFramedTransport($socket, true, true);
44+
$transport = new TFramedTransport($socket, true, true);
4645
} else {
47-
$transport = new \TBufferedTransport($socket, 1024, 1024);
46+
$transport = new TBufferedTransport($socket, 1024, 1024);
4847
}
4948

50-
$this->client = new CassandraClient(new \TBinaryProtocolAccelerated($transport));
49+
$this->client = new CassandraClient(new TBinaryProtocolAccelerated($transport));
5150
$transport->open();
5251

5352
$this->set_keyspace($keyspace);

lib/phpcassa/Index/IndexExpression.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
<?php
22
namespace phpcassa\Index;
33

4+
use cassandra\IndexOperator;
5+
46
use phpcassa\ColumnFamily;
57

68
/**
79
* @package phpcassa\Index
810
*/
911
class IndexExpression extends \cassandra\IndexExpression {
1012

13+
static protected $names_to_values = array(
14+
"EQ" => IndexOperator::EQ,
15+
"GTE" => IndexOperator::GTE,
16+
"GT" => IndexOperator::GT,
17+
"LTE" => IndexOperator::LTE,
18+
"LT" => IndexOperator::LT
19+
);
20+
1121
/**
1222
* Constructs an IndexExpression to be used in an IndexClause, which can
1323
* be used with get_indexed_slices().
@@ -25,8 +35,7 @@ public function __construct($column_name, $value, $op="EQ") {
2535
if (is_int($op)) {
2636
$this->op = $op;
2737
} else {
28-
$operators = $GLOBALS['\cassandra\E_IndexOperator'];
29-
$this->op = $operators[$op];
38+
$this->op = IndexExpression::$names_to_values[$op];
3039
}
3140
}
3241
}

test/ConnectionPoolTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Thrift\Protocol\TBinaryProtocolAccelerated;
4+
35
use phpcassa\Connection\ConnectionPool;
46
use phpcassa\Connection\MaxRetriesException;
57
use phpcassa\Connection\NoServerAvailable;

0 commit comments

Comments
 (0)