diff --git a/src/Illuminate/Foundation/Console/DocsCommand.php b/src/Illuminate/Foundation/Console/DocsCommand.php index 15dc49d6815f..e970a3c7c69e 100644 --- a/src/Illuminate/Foundation/Console/DocsCommand.php +++ b/src/Illuminate/Foundation/Console/DocsCommand.php @@ -12,6 +12,7 @@ use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Process\Exception\ProcessFailedException; +use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; use Throwable; @@ -351,7 +352,7 @@ protected function open($url) } elseif (in_array($this->systemOsFamily, ['Darwin', 'Windows', 'Linux'])) { $this->openViaBuiltInStrategy($url); } else { - $this->components->warn('Unable to open the URL on your system. You will need to open it yourself.'); + $this->components->warn('Unable to open the URL on your system. You will need to open it yourself or create a custom opener for your system.'); } })($url); } @@ -387,11 +388,19 @@ protected function openViaCustomStrategy($url) */ protected function openViaBuiltInStrategy($url) { - $process = tap(Process::fromShellCommandline(match ($this->systemOsFamily) { + $binary = (new ExecutableFinder())->find(match ($this->systemOsFamily) { 'Darwin' => 'open', 'Windows' => 'start', 'Linux' => 'xdg-open', - }.' '.escapeshellarg($url)))->run(); + }); + + if ($binary === null) { + $this->components->warn('Unable to open the URL on your system. You will need to open it yourself or create a custom opener for your system.'); + + return; + } + + $process = tap(Process::fromShellCommandline($binary.' '.escapeshellarg($url)))->run(); if (! $process->isSuccessful()) { throw new ProcessFailedException($process); diff --git a/tests/Foundation/FoundationDocsCommandTest.php b/tests/Foundation/FoundationDocsCommandTest.php index b725e2c91830..9bca29ad7a82 100644 --- a/tests/Foundation/FoundationDocsCommandTest.php +++ b/tests/Foundation/FoundationDocsCommandTest.php @@ -292,7 +292,7 @@ public function testUnknownSystemNotifiedToOpenManualy() $this->app[Kernel::class]->registerCommand($this->command()->setUrlOpener(null)->setSystemOsFamily('Laravel OS')); $this->artisan('docs validation') - ->expectsOutputToContain('Unable to open the URL on your system. You will need to open it yourself.') + ->expectsOutputToContain('Unable to open the URL on your system. You will need to open it yourself or create a custom opener for your system.') ->assertSuccessful(); }