1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 08:10:07 +01:00

Replace some \n with PHP_EOL; move custom drivers into Custom namespace

This commit is contained in:
Matt Stauffer
2022-12-21 19:54:13 -05:00
parent a4e8331852
commit 20f48f6eab
9 changed files with 58 additions and 18 deletions

View File

@@ -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();
}

View File

@@ -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.
*

View File

@@ -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();
}

View File

@@ -71,7 +71,7 @@ public static function showDirectoryListing(string $valetSitePath, string $uri)
// Output the HTML for the directory listing
echo "<h1>Index of $uri</h1>";
echo '<hr>';
echo implode("<br>\n", array_map(function ($path) use ($uri, $is_root) {
echo implode("<br>".PHP_EOL, array_map(function ($path) use ($uri, $is_root) {
$file = basename($path);
return ($is_root) ? "<a href='/$file'>/$file</a>" : "<a href='$uri/$file'>$uri/$file/</a>";

View File

@@ -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';

View File

@@ -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;
}

View File

@@ -1,6 +1,6 @@
<?php
namespace Valet\Drivers\Specific;
namespace Valet\Drivers\Custom;
use Valet\Drivers\ValetDriver;

View File

@@ -21,6 +21,7 @@ public function prepTestConfig()
}
Configuration::createConfigurationDirectory();
Configuration::createDriversDirectory();
Configuration::writeBaseConfiguration();
}

View File

@@ -42,9 +42,9 @@ public function test_fpm_is_configured_with_the_correct_user_group_and_port()
resolve(StubForUpdatingFpmConfigFiles::class)->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');