@@ -45,13 +45,15 @@ private function __construct(
4545 * This is the primary method for loading configuration with full control over sources.
4646 *
4747 * Loading order (later overrides earlier):
48- * 1. Profile from TOML file (if $configFile provided or found at default location)
48+ * 1. Profile from TOML file (if $configFile provided, or TEMPORAL_CONFIG_FILE is set,
49+ * or file exists at default platform-specific location)
4950 * 2. Environment variable overrides (if $envProvider provided)
5051 *
5152 * @param non-empty-string|null $profileName Profile name to load. If null, uses TEMPORAL_PROFILE
5253 * environment variable or 'default' as fallback.
5354 * @param non-empty-string|null $configFile Path to TOML config file or TOML content string.
54- * If null, attempts to find config at default platform-specific location.
55+ * If null, checks TEMPORAL_CONFIG_FILE env var, then checks if file exists at
56+ * default platform-specific location.
5557 * @param EnvProvider $envProvider Environment variable provider for overrides.
5658 * @param bool $strict Whether to use strict TOML parsing (validates mutual exclusivity, etc.)
5759 *
@@ -69,7 +71,14 @@ public static function load(
6971 $ profileName ??= $ envConfig ->currentProfile ?? 'default ' ;
7072 $ profileNameLower = \strtolower ($ profileName );
7173
72- // Load from file
74+ // Determine config file path: explicit > env var > default location
75+ $ configFile ??= $ envConfig ->configFile ;
76+ if ($ configFile === null ) {
77+ $ configFile = self ::getDefaultConfigPath ($ envProvider );
78+ $ configFile === null or \file_exists ($ configFile ) or $ configFile = null ;
79+ }
80+
81+ // Load from file if it exists
7382 $ profile = null ;
7483 $ profiles = [];
7584 if ($ configFile !== null ) {
@@ -181,4 +190,34 @@ private static function normalizeProfileNames(array $profiles): array
181190 }
182191 return $ normalized ;
183192 }
193+
194+ /**
195+ * Get the default configuration file path based on the operating system.
196+ *
197+ * Returns the platform-specific path to temporal.toml configuration file:
198+ * - Linux/Unix: $XDG_CONFIG_HOME/temporalio/temporal.toml (default: ~/.config/temporalio/temporal.toml)
199+ * - macOS: ~/Library/Application Support/temporalio/temporal.toml
200+ * - Windows: %APPDATA%/temporalio/temporal.toml
201+ *
202+ * Note: This method returns the expected path regardless of whether the file exists.
203+ * The caller is responsible for checking file existence.
204+ *
205+ * @param EnvProvider $envProvider Environment variable provider
206+ * @return non-empty-string|null Path to default config file, or null if home directory cannot be determined
207+ */
208+ private static function getDefaultConfigPath (EnvProvider $ envProvider ): ?string
209+ {
210+ $ home = $ envProvider ->get ('HOME ' ) ?? $ envProvider ->get ('USERPROFILE ' );
211+ if ($ home === null ) {
212+ return null ;
213+ }
214+
215+ $ configDir = match (\PHP_OS_FAMILY ) {
216+ 'Windows ' => $ envProvider ->get ('APPDATA ' ) ?? ($ home . '\\AppData \\Roaming ' ),
217+ 'Darwin ' => $ home . '/Library/Application Support ' ,
218+ default => $ envProvider ->get ('XDG_CONFIG_HOME ' ) ?? ($ home . '/.config ' ),
219+ };
220+
221+ return $ configDir . \DIRECTORY_SEPARATOR . 'temporalio ' . \DIRECTORY_SEPARATOR . 'temporal.toml ' ;
222+ }
184223}
0 commit comments