aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/lib/Grpc
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2016-09-09 11:31:25 -0700
committerGravatar Sree Kuchibhotla <sreek@google.com>2016-09-09 11:31:25 -0700
commitd0989101f520bdfe961605f198ddc50c7657011d (patch)
tree5f5f33097791f281f211bc45d4da816d9f230f53 /src/php/lib/Grpc
parent509ee4c11127700986ceb05c020d2ceef5667852 (diff)
parent61a420e9966e0b628c710bd4c2db2409bc1cfad9 (diff)
Merge branch 'master' into fix_channel_from_fd_api
Diffstat (limited to 'src/php/lib/Grpc')
-rw-r--r--src/php/lib/Grpc/AbstractCall.php37
-rw-r--r--src/php/lib/Grpc/BaseStub.php11
-rw-r--r--src/php/lib/Grpc/BidiStreamingCall.php10
-rw-r--r--src/php/lib/Grpc/ClientStreamingCall.php6
-rw-r--r--src/php/lib/Grpc/ServerStreamingCall.php12
-rw-r--r--src/php/lib/Grpc/UnaryCall.php4
6 files changed, 50 insertions, 30 deletions
diff --git a/src/php/lib/Grpc/AbstractCall.php b/src/php/lib/Grpc/AbstractCall.php
index c86d298805..c58ee56742 100644
--- a/src/php/lib/Grpc/AbstractCall.php
+++ b/src/php/lib/Grpc/AbstractCall.php
@@ -34,8 +34,15 @@
namespace Grpc;
+/**
+ * Class AbstractCall
+ * @package Grpc
+ */
abstract class AbstractCall
{
+ /**
+ * @var Call
+ */
protected $call;
protected $deserialize;
protected $metadata;
@@ -51,13 +58,15 @@ abstract class AbstractCall
* the response
* @param array $options Call options (optional)
*/
- public function __construct(Channel $channel,
- $method,
- $deserialize,
- $options = [])
- {
- if (isset($options['timeout']) &&
- is_numeric($timeout = $options['timeout'])) {
+ public function __construct(
+ Channel $channel,
+ $method,
+ $deserialize,
+ $options = []
+ ) {
+ if (array_key_exists('timeout', $options) &&
+ is_numeric($timeout = $options['timeout'])
+ ) {
$now = Timeval::now();
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
@@ -68,17 +77,19 @@ abstract class AbstractCall
$this->deserialize = $deserialize;
$this->metadata = null;
$this->trailing_metadata = null;
- if (isset($options['call_credentials_callback']) &&
+ if (array_key_exists('call_credentials_callback', $options) &&
is_callable($call_credentials_callback =
- $options['call_credentials_callback'])) {
+ $options['call_credentials_callback'])
+ ) {
$call_credentials = CallCredentials::createFromPlugin(
- $call_credentials_callback);
+ $call_credentials_callback
+ );
$this->call->setCredentials($call_credentials);
}
}
/**
- * @return The metadata sent by the server.
+ * @return mixed The metadata sent by the server.
*/
public function getMetadata()
{
@@ -86,7 +97,7 @@ abstract class AbstractCall
}
/**
- * @return The trailing metadata sent by the server.
+ * @return mixed The trailing metadata sent by the server.
*/
public function getTrailingMetadata()
{
@@ -114,7 +125,7 @@ abstract class AbstractCall
*
* @param string $value The binary value to deserialize
*
- * @return The deserialized value
+ * @return mixed The deserialized value
*/
protected function deserializeResponse($value)
{
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php
index 2fec1bd9cc..d850eebc78 100644
--- a/src/php/lib/Grpc/BaseStub.php
+++ b/src/php/lib/Grpc/BaseStub.php
@@ -41,6 +41,7 @@ namespace Grpc;
class BaseStub
{
private $hostname;
+ private $hostname_override;
private $channel;
// a callback function
@@ -75,6 +76,9 @@ class BaseStub
} else {
$opts['grpc.primary_user_agent'] = '';
}
+ if (!empty($opts['grpc.ssl_target_name_override'])) {
+ $this->hostname_override = $opts['grpc.ssl_target_name_override'];
+ }
$opts['grpc.primary_user_agent'] .=
'grpc-php/'.$package_config['version'];
if (!array_key_exists('credentials', $opts)) {
@@ -173,7 +177,12 @@ class BaseStub
}
$service_name = substr($method, 0, $last_slash_idx);
- return 'https://'.$this->hostname.$service_name;
+ if ($this->hostname_override) {
+ $hostname = $this->hostname_override;
+ } else {
+ $hostname = $this->hostname;
+ }
+ return 'https://'.$hostname.$service_name;
}
/**
diff --git a/src/php/lib/Grpc/BidiStreamingCall.php b/src/php/lib/Grpc/BidiStreamingCall.php
index c2fdb94b86..5d6ecfb275 100644
--- a/src/php/lib/Grpc/BidiStreamingCall.php
+++ b/src/php/lib/Grpc/BidiStreamingCall.php
@@ -45,7 +45,7 @@ class BidiStreamingCall extends AbstractCall
*
* @param array $metadata Metadata to send with the call, if applicable
*/
- public function start($metadata = [])
+ public function start(array $metadata = [])
{
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
@@ -55,7 +55,7 @@ class BidiStreamingCall extends AbstractCall
/**
* Reads the next value from the server.
*
- * @return The next value from the server, or null if there is none
+ * @return mixed The next value from the server, or null if there is none
*/
public function read()
{
@@ -82,7 +82,7 @@ class BidiStreamingCall extends AbstractCall
public function write($data, $options = [])
{
$message_array = ['message' => $data->serialize()];
- if (isset($options['flags'])) {
+ if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
@@ -103,8 +103,8 @@ class BidiStreamingCall extends AbstractCall
/**
* Wait for the server to send the status, and return it.
*
- * @return object The status object, with integer $code, string $details,
- * and array $metadata members
+ * @return \stdClass The status object, with integer $code, string $details,
+ * and array $metadata members
*/
public function getStatus()
{
diff --git a/src/php/lib/Grpc/ClientStreamingCall.php b/src/php/lib/Grpc/ClientStreamingCall.php
index 4050f7ed06..c96e26d033 100644
--- a/src/php/lib/Grpc/ClientStreamingCall.php
+++ b/src/php/lib/Grpc/ClientStreamingCall.php
@@ -60,10 +60,10 @@ class ClientStreamingCall extends AbstractCall
* @param array $options an array of options, possible keys:
* 'flags' => a number
*/
- public function write($data, $options = [])
+ public function write($data, array $options = [])
{
$message_array = ['message' => $data->serialize()];
- if (isset($options['flags'])) {
+ if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
@@ -74,7 +74,7 @@ class ClientStreamingCall extends AbstractCall
/**
* Wait for the server to respond with data and a status.
*
- * @return [response data, status]
+ * @return array [response data, status]
*/
public function wait()
{
diff --git a/src/php/lib/Grpc/ServerStreamingCall.php b/src/php/lib/Grpc/ServerStreamingCall.php
index ba89d9f972..5f0d42c528 100644
--- a/src/php/lib/Grpc/ServerStreamingCall.php
+++ b/src/php/lib/Grpc/ServerStreamingCall.php
@@ -36,14 +36,14 @@ namespace Grpc;
/**
* Represents an active call that sends a single message and then gets a stream
- * of reponses.
+ * of responses.
*/
class ServerStreamingCall extends AbstractCall
{
/**
* Start the call.
*
- * @param $data The data to send
+ * @param mixed $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* @param array $options an array of options, possible keys:
* 'flags' => a number
@@ -51,7 +51,7 @@ class ServerStreamingCall extends AbstractCall
public function start($data, $metadata = [], $options = [])
{
$message_array = ['message' => $data->serialize()];
- if (isset($options['flags'])) {
+ if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$event = $this->call->startBatch([
@@ -64,7 +64,7 @@ class ServerStreamingCall extends AbstractCall
}
/**
- * @return An iterator of response values
+ * @return mixed An iterator of response values
*/
public function responses()
{
@@ -82,8 +82,8 @@ class ServerStreamingCall extends AbstractCall
/**
* Wait for the server to send the status, and return it.
*
- * @return object The status object, with integer $code, string $details,
- * and array $metadata members
+ * @return \stdClass The status object, with integer $code, string $details,
+ * and array $metadata members
*/
public function getStatus()
{
diff --git a/src/php/lib/Grpc/UnaryCall.php b/src/php/lib/Grpc/UnaryCall.php
index a71b05dc93..487b89ebc1 100644
--- a/src/php/lib/Grpc/UnaryCall.php
+++ b/src/php/lib/Grpc/UnaryCall.php
@@ -43,7 +43,7 @@ class UnaryCall extends AbstractCall
/**
* Start the call.
*
- * @param $data The data to send
+ * @param mixed $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* @param array $options an array of options, possible keys:
* 'flags' => a number
@@ -66,7 +66,7 @@ class UnaryCall extends AbstractCall
/**
* Wait for the server to respond with data and a status.
*
- * @return [response data, status]
+ * @return array [response data, status]
*/
public function wait()
{