4343 */
4444final class ConfigEnv
4545{
46- public function __construct (
46+ /**
47+ * Current active profile name from TEMPORAL_PROFILE
48+ * @var non-empty-lowercase-string|null
49+ */
50+ public readonly ?string $ currentProfile ;
51+
52+ /**
53+ * Path to TOML configuration file from TEMPORAL_CONFIG_FILE
54+ * @var non-empty-string|null
55+ */
56+ public readonly ?string $ configFile ;
57+
58+ /**
59+ * @param ConfigProfile $profile Profile constructed from environment variables
60+ * @param string|null $currentProfile Current active profile name
61+ * @param string|null $configFile Path to TOML configuration file
62+ */
63+ private function __construct (
4764 /**
4865 * Profile constructed from environment variables
4966 */
5067 public readonly ConfigProfile $ profile ,
51- /**
52- * Current active profile name from TEMPORAL_PROFILE
53- * @var non-empty-lowercase-string|null
54- */
55- public readonly ?string $ currentProfile = null ,
56- /**
57- * Path to TOML configuration file from TEMPORAL_CONFIG_FILE
58- * @var non-empty-string|null
59- */
60- public readonly ?string $ configFile = null ,
61- ) {}
68+ ?string $ currentProfile = null ,
69+ ?string $ configFile = null ,
70+ ) {
71+ $ this ->currentProfile = $ currentProfile === '' || $ currentProfile === null
72+ ? null
73+ : \strtolower ($ currentProfile );
74+ $ this ->configFile = $ configFile === '' ? null : $ configFile ;
75+ }
6276
6377 public static function fromEnvProvider (EnvProvider $ env ): self
6478 {
65- $ profile = \strtolower ($ env ->get ('TEMPORAL_PROFILE ' , '' )) ?? '' ;
66- $ profile === '' and $ profile = null ;
67-
6879 return new self (
6980 new ConfigProfile (
7081 address: $ env ->get ('TEMPORAL_ADDRESS ' ),
@@ -74,7 +85,7 @@ public static function fromEnvProvider(EnvProvider $env): self
7485 grpcMeta: self ::fetchGrpcMeta ($ env ),
7586 codecConfig: self ::fetchCodecConfig ($ env ),
7687 ),
77- $ profile ,
88+ $ env -> get ( ' TEMPORAL_PROFILE ' ) ,
7889 $ env ->get ('TEMPORAL_CONFIG_FILE ' ),
7990 );
8091 }
@@ -139,6 +150,7 @@ private static function fetchGrpcMeta(EnvProvider $env): array
139150
140151 foreach ($ meta as $ key => $ value ) {
141152 // Transform header name: lowercase and replace _ with -
153+ /** @var non-empty-string $headerName */
142154 $ headerName = \str_replace ('_ ' , '- ' , $ key );
143155 $ result [$ headerName ] = $ value ;
144156 }
0 commit comments