aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2015-07-28 09:20:08 -0700
committerGravatar yang-g <yangg@google.com>2015-07-28 09:20:08 -0700
commite8afb2338f4d8ebb5cdab093aac342a4378604ab (patch)
treefaafdf066ca220466cf98500a1656292fb24188b /src/php
parent60b653bf35fad97f9b0187922ccea9cfb04f635d (diff)
parent8e06c2e62e0be2606598dd1f2a6582b585364520 (diff)
Merge remote-tracking branch 'upstream/master' into jitter
Diffstat (limited to 'src/php')
-rw-r--r--src/php/composer.json2
-rw-r--r--src/php/ext/grpc/call.c14
-rw-r--r--src/php/ext/grpc/channel.c18
-rw-r--r--src/php/ext/grpc/credentials.c11
-rw-r--r--src/php/ext/grpc/server_credentials.c19
-rw-r--r--src/php/lib/Grpc/AbstractCall.php7
-rwxr-xr-xsrc/php/lib/Grpc/BaseStub.php12
-rw-r--r--src/php/tests/generated_code/AbstractGeneratedCodeTest.php7
-rwxr-xr-xsrc/php/tests/interop/interop_client.php9
-rwxr-xr-xsrc/php/tests/unit_tests/CallTest.php4
-rwxr-xr-xsrc/php/tests/unit_tests/EndToEndTest.php8
11 files changed, 72 insertions, 39 deletions
diff --git a/src/php/composer.json b/src/php/composer.json
index b0115bdadd..2d0fe0c87a 100644
--- a/src/php/composer.json
+++ b/src/php/composer.json
@@ -1,7 +1,7 @@
{
"name": "grpc/grpc",
"description": "gRPC library for PHP",
- "version": "0.5.0",
+ "version": "0.5.1",
"homepage": "http://grpc.io",
"license": "BSD-3-Clause",
"repositories": [
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c
index b67bae7568..1f76c7359d 100644
--- a/src/php/ext/grpc/call.c
+++ b/src/php/ext/grpc/call.c
@@ -473,6 +473,16 @@ cleanup:
}
/**
+ * Get the endpoint this call/stream is connected to
+ * @return string The URI of the endpoint
+ */
+PHP_METHOD(Call, getPeer) {
+ wrapped_grpc_call *call =
+ (wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ RETURN_STRING(grpc_call_get_peer(call->wrapped), 1);
+}
+
+/**
* Cancel the call. This will cause the call to end with STATUS_CANCELLED if it
* has not already ended with another status.
*/
@@ -485,7 +495,9 @@ PHP_METHOD(Call, cancel) {
static zend_function_entry call_methods[] = {
PHP_ME(Call, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Call, startBatch, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Call, cancel, NULL, ZEND_ACC_PUBLIC) PHP_FE_END};
+ PHP_ME(Call, getPeer, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Call, cancel, NULL, ZEND_ACC_PUBLIC)
+ PHP_FE_END};
void grpc_init_call(TSRMLS_D) {
zend_class_entry ce;
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index b8262db162..7d8a6f87ab 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -152,7 +152,7 @@ PHP_METHOD(Channel, __construct) {
override = target;
override_len = target_length;
if (args_array == NULL) {
- channel->wrapped = grpc_channel_create(target, NULL);
+ channel->wrapped = grpc_insecure_channel_create(target, NULL);
} else {
array_hash = Z_ARRVAL_P(args_array);
if (zend_hash_find(array_hash, "credentials", sizeof("credentials"),
@@ -182,7 +182,7 @@ PHP_METHOD(Channel, __construct) {
}
php_grpc_read_args_array(args_array, &args);
if (creds == NULL) {
- channel->wrapped = grpc_channel_create(target, &args);
+ channel->wrapped = grpc_insecure_channel_create(target, &args);
} else {
gpr_log(GPR_DEBUG, "Initialized secure channel");
channel->wrapped =
@@ -195,6 +195,16 @@ PHP_METHOD(Channel, __construct) {
}
/**
+ * Get the endpoint this call/stream is connected to
+ * @return string The URI of the endpoint
+ */
+PHP_METHOD(Channel, getTarget) {
+ wrapped_grpc_channel *channel =
+ (wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ RETURN_STRING(grpc_channel_get_target(channel->wrapped), 1);
+}
+
+/**
* Close the channel
*/
PHP_METHOD(Channel, close) {
@@ -208,7 +218,9 @@ PHP_METHOD(Channel, close) {
static zend_function_entry channel_methods[] = {
PHP_ME(Channel, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
- PHP_ME(Channel, close, NULL, ZEND_ACC_PUBLIC) PHP_FE_END};
+ PHP_ME(Channel, getTarget, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Channel, close, NULL, ZEND_ACC_PUBLIC)
+ PHP_FE_END};
void grpc_init_channel(TSRMLS_D) {
zend_class_entry ce;
diff --git a/src/php/ext/grpc/credentials.c b/src/php/ext/grpc/credentials.c
index a262b9981f..01cb94e3aa 100644
--- a/src/php/ext/grpc/credentials.c
+++ b/src/php/ext/grpc/credentials.c
@@ -175,23 +175,12 @@ PHP_METHOD(Credentials, createGce) {
RETURN_DESTROY_ZVAL(creds_object);
}
-/**
- * Create fake credentials. Only to be used for testing.
- * @return Credentials The new fake credentials object
- */
-PHP_METHOD(Credentials, createFake) {
- grpc_credentials *creds = grpc_fake_transport_security_credentials_create();
- zval *creds_object = grpc_php_wrap_credentials(creds);
- RETURN_DESTROY_ZVAL(creds_object);
-}
-
static zend_function_entry credentials_methods[] = {
PHP_ME(Credentials, createDefault, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createSsl, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createComposite, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createGce, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
- PHP_ME(Credentials, createFake, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END};
void grpc_init_credentials(TSRMLS_D) {
diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c
index c4c1fabb1a..e9183c4598 100644
--- a/src/php/ext/grpc/server_credentials.c
+++ b/src/php/ext/grpc/server_credentials.c
@@ -115,27 +115,16 @@ PHP_METHOD(ServerCredentials, createSsl) {
"createSsl expects 3 strings", 1 TSRMLS_CC);
return;
}
- grpc_server_credentials *creds =
- grpc_ssl_server_credentials_create(pem_root_certs, &pem_key_cert_pair, 1);
- zval *creds_object = grpc_php_wrap_server_credentials(creds);
- RETURN_DESTROY_ZVAL(creds_object);
-}
-
-/**
- * Create fake credentials. Only to be used for testing.
- * @return ServerCredentials The new fake credentials object
- */
-PHP_METHOD(ServerCredentials, createFake) {
- grpc_server_credentials *creds =
- grpc_fake_transport_security_server_credentials_create();
+ /* TODO: add a force_client_auth field in ServerCredentials and pass it as
+ * the last parameter. */
+ grpc_server_credentials *creds = grpc_ssl_server_credentials_create(
+ pem_root_certs, &pem_key_cert_pair, 1, 0);
zval *creds_object = grpc_php_wrap_server_credentials(creds);
RETURN_DESTROY_ZVAL(creds_object);
}
static zend_function_entry server_credentials_methods[] = {
PHP_ME(ServerCredentials, createSsl, NULL,
- ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
- PHP_ME(ServerCredentials, createFake, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_FE_END};
void grpc_init_server_credentials(TSRMLS_D) {
diff --git a/src/php/lib/Grpc/AbstractCall.php b/src/php/lib/Grpc/AbstractCall.php
index 5b28417a0d..35057224f8 100644
--- a/src/php/lib/Grpc/AbstractCall.php
+++ b/src/php/lib/Grpc/AbstractCall.php
@@ -68,6 +68,13 @@ abstract class AbstractCall {
}
/**
+ * @return string The URI of the endpoint.
+ */
+ public function getPeer() {
+ return $this->call->getPeer();
+ }
+
+ /**
* Cancels the call
*/
public function cancel() {
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php
index 48c00977eb..a0c677908c 100755
--- a/src/php/lib/Grpc/BaseStub.php
+++ b/src/php/lib/Grpc/BaseStub.php
@@ -60,11 +60,21 @@ class BaseStub {
}
unset($opts['update_metadata']);
}
-
+ $package_config = json_decode(
+ file_get_contents(dirname(__FILE__) . '/../../composer.json'), true);
+ $opts['grpc.primary_user_agent'] =
+ 'grpc-php/' . $package_config['version'];
$this->channel = new Channel($hostname, $opts);
}
/**
+ * @return string The URI of the endpoint.
+ */
+ public function getTarget() {
+ return $this->channel->getTarget();
+ }
+
+ /**
* Close the communication channel associated with this stub
*/
public function close() {
diff --git a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
index 6102aaf0a8..8b7e67f57c 100644
--- a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
+++ b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
@@ -43,7 +43,9 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
$div_arg = new math\DivArgs();
$div_arg->setDividend(7);
$div_arg->setDivisor(4);
- list($response, $status) = self::$client->Div($div_arg)->wait();
+ $call = self::$client->Div($div_arg);
+ $this->assertTrue(is_string($call->getPeer()));
+ list($response, $status) = $call->wait();
$this->assertSame(1, $response->getQuotient());
$this->assertSame(3, $response->getRemainder());
$this->assertSame(\Grpc\STATUS_OK, $status->code);
@@ -53,6 +55,7 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
$fib_arg = new math\FibArgs();
$fib_arg->setLimit(7);
$call = self::$client->Fib($fib_arg);
+ $this->assertTrue(is_string($call->getPeer()));
$result_array = iterator_to_array($call->responses());
$extract_num = function($num){
return $num->getNum();
@@ -72,6 +75,7 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
}
};
$call = self::$client->Sum($num_iter());
+ $this->assertTrue(is_string($call->getPeer()));
list($response, $status) = $call->wait();
$this->assertSame(21, $response->getNum());
$this->assertSame(\Grpc\STATUS_OK, $status->code);
@@ -79,6 +83,7 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
public function testBidiStreaming() {
$call = self::$client->DivMany();
+ $this->assertTrue(is_string($call->getPeer()));
for ($i = 0; $i < 7; $i++) {
$div_arg = new math\DivArgs();
$div_arg->setDividend(2 * $i + 1);
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 2041577557..44e6242c29 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -332,10 +332,11 @@ if (in_array($args['test_case'], array(
$opts['update_metadata'] = $auth->getUpdateMetadataFunc();
}
-$stub = new grpc\testing\TestServiceClient(
- new Grpc\BaseStub(
- $server_address,
- $opts));
+$internal_stub = new Grpc\BaseStub($server_address, $opts);
+hardAssert(is_string($internal_stub->getTarget()),
+ 'Unexpected target URI value');
+
+$stub = new grpc\testing\TestServiceClient($internal_stub);
echo "Connecting to $server_address\n";
echo "Running test case $args[test_case]\n";
diff --git a/src/php/tests/unit_tests/CallTest.php b/src/php/tests/unit_tests/CallTest.php
index 77a2d86ce4..caff15ee11 100755
--- a/src/php/tests/unit_tests/CallTest.php
+++ b/src/php/tests/unit_tests/CallTest.php
@@ -79,4 +79,8 @@ class CallTest extends PHPUnit_Framework_TestCase{
$result = $this->call->startBatch($batch);
$this->assertTrue($result->send_metadata);
}
+
+ public function testGetPeer() {
+ $this->assertTrue(is_string($this->call->getPeer()));
+ }
}
diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php
index 2980dca4a7..27e27cdfdf 100755
--- a/src/php/tests/unit_tests/EndToEndTest.php
+++ b/src/php/tests/unit_tests/EndToEndTest.php
@@ -34,8 +34,8 @@
class EndToEndTest extends PHPUnit_Framework_TestCase{
public function setUp() {
$this->server = new Grpc\Server([]);
- $port = $this->server->addHttp2Port('0.0.0.0:0');
- $this->channel = new Grpc\Channel('localhost:' . $port, []);
+ $this->port = $this->server->addHttp2Port('0.0.0.0:0');
+ $this->channel = new Grpc\Channel('localhost:' . $this->port, []);
$this->server->start();
}
@@ -149,4 +149,8 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
unset($call);
unset($server_call);
}
+
+ public function testGetTarget() {
+ $this->assertTrue(is_string($this->channel->getTarget()));
+ }
}