aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/lib/Grpc
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-04-20 14:13:54 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-04-21 14:27:41 -0700
commit2c9c76310e78ca3a64018d2aabc5ee54e98a8ea9 (patch)
treeb2664ab0e355fd9c0e86ab58d7ffb47d07d4f9a5 /src/php/lib/Grpc
parent3cdb3b627e4d43806567c6591b5691cd1b6d36d2 (diff)
Support update metadata callback function in php BaseStub
Diffstat (limited to 'src/php/lib/Grpc')
-rwxr-xr-xsrc/php/lib/Grpc/BaseStub.php45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php
index fc83dace20..cb2537fe98 100755
--- a/src/php/lib/Grpc/BaseStub.php
+++ b/src/php/lib/Grpc/BaseStub.php
@@ -41,7 +41,24 @@ class BaseStub {
private $channel;
+ // a callback function
+ private $update_metadata;
+
+ /**
+ * @param $hostname string
+ * @param $opts array
+ * - 'update_metadata': (optional) a callback function which takes in a
+ * metadata array, and returns an updated metadata array
+ */
public function __construct($hostname, $opts) {
+ $this->update_metadata = null;
+ if (isset($opts['update_metadata'])) {
+ if (is_callable($opts['update_metadata'])) {
+ $this->update_metadata = $opts['update_metadata'];
+ }
+ unset($opts['update_metadata']);
+ }
+
$this->channel = new Channel($hostname, $opts);
}
@@ -69,7 +86,12 @@ class BaseStub {
callable $deserialize,
$metadata = array()) {
$call = new UnaryCall($this->channel, $method, $deserialize);
- $call->start($argument, $metadata);
+ $actual_metadata = $metadata;
+ if (is_callable($this->update_metadata)) {
+ $actual_metadata = call_user_func($this->update_metadata,
+ $actual_metadata);
+ }
+ $call->start($argument, $actual_metadata);
return $call;
}
@@ -89,7 +111,12 @@ class BaseStub {
callable $deserialize,
$metadata = array()) {
$call = new ClientStreamingCall($this->channel, $method, $deserialize);
- $call->start($arguments, $metadata);
+ $actual_metadata = $metadata;
+ if (is_callable($this->update_metadata)) {
+ $actual_metadata = call_user_func($this->update_metadata,
+ $actual_metadata);
+ }
+ $call->start($arguments, $actual_metadata);
return $call;
}
@@ -108,7 +135,12 @@ class BaseStub {
callable $deserialize,
$metadata = array()) {
$call = new ServerStreamingCall($this->channel, $method, $deserialize);
- $call->start($argument, $metadata);
+ $actual_metadata = $metadata;
+ if (is_callable($this->update_metadata)) {
+ $actual_metadata = call_user_func($this->update_metadata,
+ $actual_metadata);
+ }
+ $call->start($argument, $actual_metadata);
return $call;
}
@@ -124,7 +156,12 @@ class BaseStub {
callable $deserialize,
$metadata = array()) {
$call = new BidiStreamingCall($this->channel, $method, $deserialize);
- $call->start($metadata);
+ $actual_metadata = $metadata;
+ if (is_callable($this->update_metadata)) {
+ $actual_metadata = call_user_func($this->update_metadata,
+ $actual_metadata);
+ }
+ $call->start($actual_metadata);
return $call;
}
}