mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
Refactor code for restarting specific PHP version
This commit is contained in:
37
cli/app.php
37
cli/app.php
@@ -495,27 +495,32 @@ 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 '':
|
||||||
|
DnsMasq::restart();
|
||||||
|
PhpFpm::restart();
|
||||||
|
Nginx::restart();
|
||||||
|
|
||||||
if ($service == '') {
|
return info('Valet services have been restarted.');
|
||||||
DnsMasq::restart();
|
case 'dnsmasq':
|
||||||
PhpFpm::restart();
|
DnsMasq::restart();
|
||||||
Nginx::restart();
|
|
||||||
|
|
||||||
return info('Valet services have been restarted.');
|
return info('dnsmasq has been restarted.');
|
||||||
} elseif ($service == 'dnsmasq') {
|
case 'nginx':
|
||||||
DnsMasq::restart();
|
Nginx::restart();
|
||||||
|
|
||||||
return info('dnsmasq has been restarted.');
|
return info('Nginx has been restarted.');
|
||||||
} elseif ($service == 'nginx') {
|
case 'php':
|
||||||
Nginx::restart();
|
PhpFpm::restart();
|
||||||
|
|
||||||
return info('Nginx has been restarted.');
|
return info('PHP has been restarted.');
|
||||||
} elseif ($serviceContainsPhp) {
|
}
|
||||||
$hasSpecifiedVersion = $service !== 'php';
|
|
||||||
PhpFpm::restart($hasSpecifiedVersion ? PhpFpm::normalizePhpVersion($service) : null);
|
|
||||||
|
|
||||||
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));
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user