Skip to content

Commit 93920bd

Browse files
committed
Add ServiceClient::createDefaultConnection() method
1 parent 6e710e3 commit 93920bd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Client/GRPC/BaseClient.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,30 @@ public static function createSSL(
166166
return new static(static fn(): WorkflowServiceClient => new WorkflowServiceClient($address, $options));
167167
}
168168

169+
/**
170+
* Create a new connection with settings from environment variables.
171+
* It automatically detects if SSL connection is required.
172+
*
173+
* @psalm-suppress RiskyTruthyFalsyComparison
174+
*/
175+
public static function createDefaultConnection(): static
176+
{
177+
$address = \getenv('TEMPORAL_ADDRESS') ?: '127.0.0.1:7233';
178+
$authKey = \getenv('TEMPORAL_AUTH_KEY') ?: '';
179+
$sslPrivateKey = \getenv('TEMPORAL_SSL_PRIVATE_KEY') ?: null;
180+
$sslCertChain = \getenv('TEMPORAL_SSL_CERTIFICATE_CHAIN') ?: null;
181+
182+
// Check SSL connection is required
183+
$useSsl = $authKey !== '' || $sslPrivateKey !== null || $sslCertChain !== null;
184+
185+
if (!$useSsl) {
186+
return static::create($address);
187+
}
188+
189+
return static::createSSL($address, clientKey: $sslPrivateKey, clientPem: $sslCertChain)
190+
->withAuthKey($authKey);
191+
}
192+
169193
/**
170194
* @param null|Pipeline<GrpcClientInterceptor, object> $pipeline
171195
*

0 commit comments

Comments
 (0)