diff --git a/cli/Valet/Configuration.php b/cli/Valet/Configuration.php index 53396a0..226019f 100644 --- a/cli/Valet/Configuration.php +++ b/cli/Valet/Configuration.php @@ -182,7 +182,8 @@ public function prependPath(string $path): void public function removePath(string $path): void { if ($path == VALET_HOME_PATH.'/Sites') { - info("Cannot remove this directory because this is where Valet stores its site definitions.\nRun [valet paths] for a list of parked paths."); + info("Cannot remove this directory because this is where Valet stores its site definitions."); + info("Run [valet paths] for a list of parked paths."); exit(); } diff --git a/cli/Valet/Drivers/ValetDriver.php b/cli/Valet/Drivers/ValetDriver.php index b6d0706..2c224e0 100644 --- a/cli/Valet/Drivers/ValetDriver.php +++ b/cli/Valet/Drivers/ValetDriver.php @@ -57,7 +57,7 @@ public static function assign(string $sitePath, string $siteName, string $uri): } // Queue custom drivers for this environment - $drivers = array_merge($drivers, static::driversIn(VALET_HOME_PATH.'/Drivers')); + $drivers = array_merge($drivers, static::customDrivers()); // Queue Valet-shipped drivers $drivers[] = 'LaravelValetDriver'; @@ -126,6 +126,13 @@ public static function specificDrivers(): array }, static::driversIn(__DIR__.'/Specific')); } + public static function customDrivers(): array + { + return array_map(function ($item) { + return 'Custom\\' . $item; + }, static::driversIn(VALET_HOME_PATH.'/Drivers')); + } + /** * Take any steps necessary before loading the front controller for this driver. * diff --git a/cli/Valet/Nginx.php b/cli/Valet/Nginx.php index 882700a..9634980 100644 --- a/cli/Valet/Nginx.php +++ b/cli/Valet/Nginx.php @@ -95,7 +95,7 @@ public function installNginxDirectory(): void $this->files->mkdirAsUser($nginxDirectory); } - $this->files->putAsUser($nginxDirectory.'/.keep', "\n"); + $this->files->putAsUser($nginxDirectory.'/.keep', PHP_EOL); $this->rewriteSecureNginxFiles(); } diff --git a/cli/Valet/Server.php b/cli/Valet/Server.php index 6b8dee1..fac2015 100644 --- a/cli/Valet/Server.php +++ b/cli/Valet/Server.php @@ -71,7 +71,7 @@ public static function showDirectoryListing(string $valetSitePath, string $uri) // Output the HTML for the directory listing echo "

Index of $uri

"; echo '
'; - echo implode("
\n", array_map(function ($path) use ($uri, $is_root) { + echo implode("
".PHP_EOL, array_map(function ($path) use ($uri, $is_root) { $file = basename($path); return ($is_root) ? "/$file" : "$uri/$file/"; diff --git a/cli/Valet/Upgrader.php b/cli/Valet/Upgrader.php index f59d6ae..bf0b218 100644 --- a/cli/Valet/Upgrader.php +++ b/cli/Valet/Upgrader.php @@ -11,6 +11,20 @@ public function __construct(public Filesystem $files) { } + /** + * Run all the upgrades that should be run every time Valet commands are run. + * + * @return void + */ + public function onEveryRun(): void + { + $this->relocateOldConfig(); + $this->pruneMissingDirectories(); + $this->pruneSymbolicLinks(); + $this->fixOldSampleValetDriver(); + $this->errorIfOldCustomDrivers(); + } + /** * Relocate config dir to ~/.config/valet/ if found in old location. * @@ -23,17 +37,33 @@ public function relocateOldConfig() } } - public function pruneMissingDirectories() + /** + * Prune all non-existent paths from the configuration. + * + * @return void + */ + public function pruneMissingDirectories(): void { Configuration::prune(); } - public function pruneSymbolicLinks() + /** + * Remove all broken symbolic links in the Valet config Sites diretory. + * + * @return void + */ + public function pruneSymbolicLinks(): void { Site::pruneLinks(); } - public function fixOldSampleValetDriver() + /** + * If the user has the old `SampleValetDriver` without the Valet namespace, + * replace it with the new `SampleValetDriver` that uses the namespace. + * + * @return void + */ + public function fixOldSampleValetDriver(): void { $samplePath = VALET_HOME_PATH.'/Drivers/SampleValetDriver.php'; @@ -47,7 +77,12 @@ public function fixOldSampleValetDriver() } } - public function errorIfOldCustomDrivers() + /** + * Throw an exception if the user has old (non-namespaced) custom drivers. + * + * @return void + */ + public function errorIfOldCustomDrivers(): void { $driversPath = VALET_HOME_PATH.'/Drivers'; diff --git a/cli/app.php b/cli/app.php index 58da810..a397191 100644 --- a/cli/app.php +++ b/cli/app.php @@ -43,11 +43,7 @@ function (ConsoleCommandEvent $event) { writer($event->getOutput()); }); -Upgrader::relocateOldConfig(); -Upgrader::pruneMissingDirectories(); -Upgrader::pruneSymbolicLinks(); -Upgrader::fixOldSampleValetDriver(); -Upgrader::errorIfOldCustomDrivers(); +Upgrader::onEveryRun(); /** * Install Valet and any required services. @@ -556,7 +552,7 @@ function (ConsoleCommandEvent $event) { if ($phpVersion = Site::phpRcVersion($site)) { info("Found '{$site}/.valetphprc' specifying version: {$phpVersion}"); } else { - info("\nPlease provide a version number. E.g.:"); + info(PHP_EOL."Please provide a version number. E.g.:"); info('valet isolate php@8.2'); exit; } diff --git a/cli/stubs/SampleValetDriver.php b/cli/stubs/SampleValetDriver.php index 1198160..3692518 100644 --- a/cli/stubs/SampleValetDriver.php +++ b/cli/stubs/SampleValetDriver.php @@ -1,6 +1,6 @@ createConfigurationFiles('php@7.2'); $contents = file_get_contents(__DIR__.'/output/fpm.conf'); - $this->assertStringContainsString(sprintf("\nuser = %s", user()), $contents); - $this->assertStringContainsString("\ngroup = staff", $contents); - $this->assertStringContainsString("\nlisten = ".VALET_HOME_PATH.'/valet72.sock', $contents); + $this->assertStringContainsString(sprintf(PHP_EOL."user = %s", user()), $contents); + $this->assertStringContainsString(PHP_EOL."group = staff", $contents); + $this->assertStringContainsString(PHP_EOL."listen = ".VALET_HOME_PATH.'/valet72.sock', $contents); // It should disable old or default FPM Pool configuration $this->assertFileDoesNotExist(__DIR__.'/output/www.conf');