aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/lib/Grpc/BaseStub.php
diff options
context:
space:
mode:
authorGravatar Tim Emiola <tbetbetbe@users.noreply.github.com>2015-04-21 15:38:32 -0700
committerGravatar Tim Emiola <tbetbetbe@users.noreply.github.com>2015-04-21 15:38:32 -0700
commit45fd72ecf5c1ad67f12f90f0458c335345d502ae (patch)
tree7981cc7c7d75349082e6e031bb3ce046f008e0f2 /src/php/lib/Grpc/BaseStub.php
parent3cdb3b627e4d43806567c6591b5691cd1b6d36d2 (diff)
parent9bd0c64d66e67e70bc0a8707280bd31b3f0da799 (diff)
Merge pull request #1332 from stanley-cheung/php_basestub_metadata_callback
Support update metadata callback function in php BaseStub
Diffstat (limited to 'src/php/lib/Grpc/BaseStub.php')
-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;
}
}