From 31676f36b1c58543697a9ea5e2a84961601b8156 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 16 May 2018 16:45:20 -0700 Subject: 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(-) (limited to 'src/php') diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index 0966193107..489d96c8aa 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); } /** -- cgit v1.2.3 From 6d96a9a6126fb94a3e0975ddfdf0791fb81e6060 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 16 May 2018 17:06:48 -0700 Subject: Provide hostname to getDefaultChannel --- src/php/lib/Grpc/BaseStub.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/php') diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index 489d96c8aa..b9c50b1da6 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'), -- cgit v1.2.3