1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 16:40:05 +01:00

Refactor code for restarting specific PHP version

This commit is contained in:
Matt Stauffer
2024-05-31 18:41:34 -04:00
parent 2399ca90d7
commit cba22f38bc
2 changed files with 23 additions and 18 deletions

View File

@@ -495,29 +495,34 @@ function (ConsoleCommandEvent $event) {
* Restart the daemon services. * Restart the daemon services.
*/ */
$app->command('restart [service]', function (OutputInterface $output, $service) { $app->command('restart [service]', function (OutputInterface $output, $service) {
$serviceContainsPhp = is_string($service) && false !== strpos($service, 'php'); switch ($service) {
case '':
if ($service == '') {
DnsMasq::restart(); DnsMasq::restart();
PhpFpm::restart(); PhpFpm::restart();
Nginx::restart(); Nginx::restart();
return info('Valet services have been restarted.'); return info('Valet services have been restarted.');
} elseif ($service == 'dnsmasq') { case 'dnsmasq':
DnsMasq::restart(); DnsMasq::restart();
return info('dnsmasq has been restarted.'); return info('dnsmasq has been restarted.');
} elseif ($service == 'nginx') { case 'nginx':
Nginx::restart(); Nginx::restart();
return info('Nginx has been restarted.'); return info('Nginx has been restarted.');
} elseif ($serviceContainsPhp) { case 'php':
$hasSpecifiedVersion = $service !== 'php'; PhpFpm::restart();
PhpFpm::restart($hasSpecifiedVersion ? PhpFpm::normalizePhpVersion($service) : null);
return info('PHP has been restarted.'); return info('PHP has been restarted.');
} }
// Handle restarting specific PHP version (e.g. `valet restart php@8.2`)
if (str_contains($service, 'php')) {
PhpFpm::restart($normalized = PhpFpm::normalizePhpVersion($service));
return info($normalized . ' has been restarted.');
}
return warning(sprintf('Invalid valet service name [%s]', $service)); return warning(sprintf('Invalid valet service name [%s]', $service));
})->descriptions('Restart the Valet services'); })->descriptions('Restart the Valet services');

View File

@@ -792,7 +792,7 @@ public function test_restart_command_restarts_php_version()
$tester->run(['command' => 'restart', 'service' => 'php@8.1']); $tester->run(['command' => 'restart', 'service' => 'php@8.1']);
$tester->assertCommandIsSuccessful(); $tester->assertCommandIsSuccessful();
$this->assertStringContainsString('PHP has been restarted.', $tester->getDisplay()); $this->assertStringContainsString('php@8.1 has been restarted.', $tester->getDisplay());
} }
public function test_restart_command_restarts_php_denormalized_version() public function test_restart_command_restarts_php_denormalized_version()
@@ -813,7 +813,7 @@ public function test_restart_command_restarts_php_denormalized_version()
$tester->run(['command' => 'restart', 'service' => 'php81']); $tester->run(['command' => 'restart', 'service' => 'php81']);
$tester->assertCommandIsSuccessful(); $tester->assertCommandIsSuccessful();
$this->assertStringContainsString('PHP has been restarted.', $tester->getDisplay()); $this->assertStringContainsString('php@8.1 has been restarted.', $tester->getDisplay());
} }
public function test_start_command() public function test_start_command()