From 0f67fab7e3d4c3bc7e31bb0ee51f7ee5cd9af2d8 Mon Sep 17 00:00:00 2001 From: botzkobg Date: Tue, 28 Jan 2025 14:58:40 +0000 Subject: [PATCH] `Grpc\ChannelCredentials` (`php-grpc` extension) is optional when `PUBSUB_EMULATOR_HOST` is set --- PubSub/src/V1/Client/PublisherClient.php | 4 +++- PubSub/src/V1/Client/SchemaServiceClient.php | 4 +++- PubSub/src/V1/Client/SubscriberClient.php | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/PubSub/src/V1/Client/PublisherClient.php b/PubSub/src/V1/Client/PublisherClient.php index fc4d8b786676..99a9493a8c56 100644 --- a/PubSub/src/V1/Client/PublisherClient.php +++ b/PubSub/src/V1/Client/PublisherClient.php @@ -685,7 +685,9 @@ private function setDefaultEmulatorConfig(array $options): array } $options['apiEndpoint'] ??= $emulatorHost; - $options['transportConfig']['grpc']['stubOpts']['credentials'] ??= ChannelCredentials::createInsecure(); + if (class_exists(ChannelCredentials::class)) { + $options['transportConfig']['grpc']['stubOpts']['credentials'] ??= ChannelCredentials::createInsecure(); + } $options['credentials'] ??= new InsecureCredentialsWrapper(); return $options; } diff --git a/PubSub/src/V1/Client/SchemaServiceClient.php b/PubSub/src/V1/Client/SchemaServiceClient.php index f33c851813b3..7a6429680fe2 100644 --- a/PubSub/src/V1/Client/SchemaServiceClient.php +++ b/PubSub/src/V1/Client/SchemaServiceClient.php @@ -633,7 +633,9 @@ private function setDefaultEmulatorConfig(array $options): array } $options['apiEndpoint'] ??= $emulatorHost; - $options['transportConfig']['grpc']['stubOpts']['credentials'] ??= ChannelCredentials::createInsecure(); + if (class_exists(ChannelCredentials::class)) { + $options['transportConfig']['grpc']['stubOpts']['credentials'] ??= ChannelCredentials::createInsecure(); + } $options['credentials'] ??= new InsecureCredentialsWrapper(); return $options; } diff --git a/PubSub/src/V1/Client/SubscriberClient.php b/PubSub/src/V1/Client/SubscriberClient.php index 7c5b77c387c4..6bedb3c0cb61 100644 --- a/PubSub/src/V1/Client/SubscriberClient.php +++ b/PubSub/src/V1/Client/SubscriberClient.php @@ -934,7 +934,9 @@ private function setDefaultEmulatorConfig(array $options): array } $options['apiEndpoint'] ??= $emulatorHost; - $options['transportConfig']['grpc']['stubOpts']['credentials'] ??= ChannelCredentials::createInsecure(); + if (class_exists(ChannelCredentials::class)) { + $options['transportConfig']['grpc']['stubOpts']['credentials'] ??= ChannelCredentials::createInsecure(); + } $options['credentials'] ??= new InsecureCredentialsWrapper(); return $options; }