Merge pull request #6634 from stanley-cheung/php-add-channel-to-stub-constructor

PHP: add optional channel argument to BaseStub constructor
pull/6895/head
Jan Tattermusch 9 years ago committed by GitHub
commit 7d670f5c87
  1. 11
      src/php/lib/Grpc/BaseStub.php

@ -52,8 +52,9 @@ class BaseStub
* - 'update_metadata': (optional) a callback function which takes in a
* metadata array, and returns an updated metadata array
* - 'grpc.primary_user_agent': (optional) a user-agent string
* @param $channel Channel An already created Channel object
*/
public function __construct($hostname, $opts)
public function __construct($hostname, $opts, $channel = null)
{
$this->hostname = $hostname;
$this->update_metadata = null;
@ -77,8 +78,16 @@ class BaseStub
'required. Please see one of the '.
'ChannelCredentials::create methods');
}
if ($channel) {
if (!is_a($channel, 'Channel')) {
throw new \Exception("The channel argument is not a".
"Channel object");
}
$this->channel = $channel;
} else {
$this->channel = new Channel($hostname, $opts);
}
}
/**
* @return string The URI of the endpoint.

Loading…
Cancel
Save