Skip to content

Commit ec91239

Browse files
committed
Add ServiceClient::createDefaultConnection() method
1 parent 8cdcc18 commit ec91239

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
@@ -164,6 +164,30 @@ public static function createSSL(
164164
return new static(static fn(): WorkflowServiceClient => new WorkflowServiceClient($address, $options));
165165
}
166166

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

0 commit comments

Comments
 (0)