From 022009144d5b4caa4475a2022c8387c619658cae Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Sun, 15 Mar 2026 05:34:51 +0000 Subject: [PATCH 1/3] refactor: extract "missing default config keys" code into a new method. - Extracted "missing default config keys" code from `writeBaseConfiguration` into a new `addMissingDefaultConfigKeys` method. --- cli/Valet/Configuration.php | 42 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/cli/Valet/Configuration.php b/cli/Valet/Configuration.php index 6492809e4..d4f14ecd5 100644 --- a/cli/Valet/Configuration.php +++ b/cli/Valet/Configuration.php @@ -149,6 +149,7 @@ public function createXdebugDirectory() { * Write the base, initial configuration for Valet. */ public function writeBaseConfiguration() { + // If the configuration file doesn't exist, create it with the base configuration. if (!$this->files->exists($this->path())) { $baseConfig = [ 'tld' => 'test', @@ -161,21 +162,8 @@ public function writeBaseConfiguration() { $this->write($baseConfig); } - $config = $this->read(); - - // Add default_php if missing or is null. - if (!isset($config['default_php']) || $config['default_php'] === null) { - $this->addDefaultPhp(); - } - - // Add tld if missing. - $this->updateKey('tld', $config['tld'] ?? 'test'); - // Add php_port if missing. - $this->updateKey('php_port', $config['php_port'] ?? PhpCgi::PORT); - // Add the default php_xdebug_port if missing. - $this->updateKey('php_xdebug_port', $config['php_xdebug_port'] ?? PhpCgiXdebug::PORT); - // Add share-tool if missing. - $this->updateKey('share-tool', $config['share-tool'] ?? 'ngrok'); + // If the configuration file exists, ensure it has all the necessary keys. + $this->addMissingDefaultConfigKeys(); } /** @@ -489,4 +477,28 @@ public function path(): string { protected function valetHomePath(string $path = ''): string { return Valet::homePath($path); } + + /** + * Add any missing necessary default configuration keys. + * + * It will not overwrite any existing configuration values, + * only add missing keys with default values. + */ + public function addMissingDefaultConfigKeys() { + $config = $this->read(); + + // Add default_php if missing or is null. + if (!isset($config['default_php']) || $config['default_php'] === null) { + $this->addDefaultPhp(); + } + + // Add tld if missing. + $this->updateKey('tld', $config['tld'] ?? 'test'); + // Add php_port if missing. + $this->updateKey('php_port', $config['php_port'] ?? PhpCgi::PORT); + // Add the default php_xdebug_port if missing. + $this->updateKey('php_xdebug_port', $config['php_xdebug_port'] ?? PhpCgiXdebug::PORT); + // Add share-tool if missing. + $this->updateKey('share-tool', $config['share-tool'] ?? 'ngrok'); + } } From 85a1cca9942f7c5c2d1f4f66e1f1c69a8fc83702 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Sun, 15 Mar 2026 05:39:54 +0000 Subject: [PATCH 2/3] refactor: move `addMissingDefaultConfigKeys` method up the file. - Moved `addMissingDefaultConfigKeys` method up the file to below the `writeBaseConfiguration` method. The only reason the method was added at the bottom of the file was to allow git diff to work out the real diff when committing. Otherwise the diff was weird. --- cli/Valet/Configuration.php | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/cli/Valet/Configuration.php b/cli/Valet/Configuration.php index d4f14ecd5..a129d2cc5 100644 --- a/cli/Valet/Configuration.php +++ b/cli/Valet/Configuration.php @@ -166,6 +166,30 @@ public function writeBaseConfiguration() { $this->addMissingDefaultConfigKeys(); } + /** + * Add any missing necessary default configuration keys. + * + * It will not overwrite any existing configuration values, + * only add missing keys with default values. + */ + public function addMissingDefaultConfigKeys() { + $config = $this->read(); + + // Add default_php if missing or is null. + if (!isset($config['default_php']) || $config['default_php'] === null) { + $this->addDefaultPhp(); + } + + // Add tld if missing. + $this->updateKey('tld', $config['tld'] ?? 'test'); + // Add php_port if missing. + $this->updateKey('php_port', $config['php_port'] ?? PhpCgi::PORT); + // Add the default php_xdebug_port if missing. + $this->updateKey('php_xdebug_port', $config['php_xdebug_port'] ?? PhpCgiXdebug::PORT); + // Add share-tool if missing. + $this->updateKey('share-tool', $config['share-tool'] ?? 'ngrok'); + } + /** * Forcefully delete the Valet home configuration directory and contents. */ @@ -477,28 +501,4 @@ public function path(): string { protected function valetHomePath(string $path = ''): string { return Valet::homePath($path); } - - /** - * Add any missing necessary default configuration keys. - * - * It will not overwrite any existing configuration values, - * only add missing keys with default values. - */ - public function addMissingDefaultConfigKeys() { - $config = $this->read(); - - // Add default_php if missing or is null. - if (!isset($config['default_php']) || $config['default_php'] === null) { - $this->addDefaultPhp(); - } - - // Add tld if missing. - $this->updateKey('tld', $config['tld'] ?? 'test'); - // Add php_port if missing. - $this->updateKey('php_port', $config['php_port'] ?? PhpCgi::PORT); - // Add the default php_xdebug_port if missing. - $this->updateKey('php_xdebug_port', $config['php_xdebug_port'] ?? PhpCgiXdebug::PORT); - // Add share-tool if missing. - $this->updateKey('share-tool', $config['share-tool'] ?? 'ngrok'); - } } From f76b13555903edb41cfcd8cd3db4d160ac2143c2 Mon Sep 17 00:00:00 2001 From: yCodeTech Date: Sun, 15 Mar 2026 05:44:04 +0000 Subject: [PATCH 3/3] feat: add Upgrader method to run `addMissingDefaultConfigKeys`. - Added new `addMissingConfigKeys` Upgrader method to run the `Configuration::addMissingConfigKeys` method on every Valet run. --- cli/Valet/Upgrader.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/Valet/Upgrader.php b/cli/Valet/Upgrader.php index a42cf6d8d..53cd19ef9 100644 --- a/cli/Valet/Upgrader.php +++ b/cli/Valet/Upgrader.php @@ -36,6 +36,7 @@ public function onEveryRun() { $this->lintNginxConfigs(); $this->upgradeNginxSiteConfigs(); $this->fixOldSampleValetDriver(); + $this->addMissingConfigKeys(); } } @@ -191,4 +192,11 @@ public function fixOldSampleValetDriver(): void { } } } + + /** + * Add any missing necessary default configuration keys. + */ + public function addMissingConfigKeys() { + $this->config->addMissingDefaultConfigKeys(); + } }