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 @@ -164,6 +164,30 @@ public static function createSSL(
164
164
return new static (static fn (): WorkflowServiceClient => new WorkflowServiceClient ($ address , $ options ));
165
165
}
166
166
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
+
167
191
/**
168
192
* @param null|Pipeline<GrpcClientInterceptor, object> $pipeline
169
193
*
You can’t perform that action at this time.
0 commit comments