File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,30 @@ public static function createSSL(
166
166
return new static (static fn (): WorkflowServiceClient => new WorkflowServiceClient ($ address , $ options ));
167
167
}
168
168
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
+
169
193
/**
170
194
* @param null|Pipeline<GrpcClientInterceptor, object> $pipeline
171
195
*
You can’t perform that action at this time.
0 commit comments