From 31676f36b1c58543697a9ea5e2a84961601b8156 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 16 May 2018 16:45:20 -0700 Subject: [PATCH 1/2] Surface a static method to fetch the default Channel that a BaseStub would create --- src/php/lib/Grpc/BaseStub.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index 09661931075..489d96c8aae 100644 --- a/src/php/lib/Grpc/BaseStub.php +++ b/src/php/lib/Grpc/BaseStub.php @@ -69,6 +69,18 @@ class BaseStub return; } + $this->channel = static::getDefaultChannel($opts); + } + + /** + * Creates and returns the default Channel + * + * @param array $opts Channel constructor options + * + * @return Channel The channel + */ + public static function getDefaultChannel(array $opts) + { $package_config = json_decode( file_get_contents(dirname(__FILE__).'/../../composer.json'), true @@ -85,7 +97,7 @@ class BaseStub 'required. Please see one of the '. 'ChannelCredentials::create methods'); } - $this->channel = new Channel($hostname, $opts); + return new Channel($hostname, $opts); } /** From 6d96a9a6126fb94a3e0975ddfdf0791fb81e6060 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 16 May 2018 17:06:48 -0700 Subject: [PATCH 2/2] Provide hostname to getDefaultChannel --- src/php/lib/Grpc/BaseStub.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index 489d96c8aae..b9c50b1da68 100644 --- a/src/php/lib/Grpc/BaseStub.php +++ b/src/php/lib/Grpc/BaseStub.php @@ -69,7 +69,7 @@ class BaseStub return; } - $this->channel = static::getDefaultChannel($opts); + $this->channel = static::getDefaultChannel($hostname, $opts); } /** @@ -79,7 +79,7 @@ class BaseStub * * @return Channel The channel */ - public static function getDefaultChannel(array $opts) + public static function getDefaultChannel($hostname, array $opts) { $package_config = json_decode( file_get_contents(dirname(__FILE__).'/../../composer.json'),