Skip to content

Commit 8ec6dbd

Browse files
xiCO2ktaylorotwell
andauthored
[5.x] Fixes issue if there is no herd or valet installed (#343)
* Fixes issue if there is no `herd` or `valet` installed. * style: fixes * Update NewCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0094be6 commit 8ec6dbd

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/NewCommand.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Input\InputOption;
1313
use Symfony\Component\Console\Output\OutputInterface;
14+
use Symfony\Component\Process\Exception\ProcessStartFailedException;
1415
use Symfony\Component\Process\PhpExecutableFinder;
1516
use Symfony\Component\Process\Process;
1617

@@ -760,17 +761,7 @@ protected function generateAppUrl($name)
760761
*/
761762
protected function getTld()
762763
{
763-
foreach (['herd', 'valet'] as $tool) {
764-
$process = new Process([$tool, 'tld', '-v']);
765-
766-
$process->run();
767-
768-
if ($process->isSuccessful()) {
769-
return trim($process->getOutput());
770-
}
771-
}
772-
773-
return 'test';
764+
return $this->runOnValetOrHerd('tld') ?? 'test';
774765
}
775766

776767
/**
@@ -792,19 +783,9 @@ protected function canResolveHostname($hostname)
792783
*/
793784
protected function isParked(string $directory)
794785
{
795-
foreach (['herd', 'valet'] as $tool) {
796-
$process = new Process([$tool, 'paths', '-v']);
786+
$output = $this->runOnValetOrHerd('paths');
797787

798-
$process->run();
799-
800-
if ($process->isSuccessful()) {
801-
$output = json_decode(trim($process->getOutput()));
802-
803-
return in_array(dirname($directory), $output);
804-
}
805-
}
806-
807-
return false;
788+
return $output !== false ? in_array(dirname($directory), json_decode($output)) : false;
808789
}
809790

810791
/**
@@ -846,6 +827,30 @@ protected function phpBinary()
846827
: 'php';
847828
}
848829

830+
/**
831+
* Runs the given command on the "herd" or "valet" CLI.
832+
*
833+
* @param string $command
834+
* @return string|bool
835+
*/
836+
protected function runOnValetOrHerd(string $command)
837+
{
838+
foreach (['herd', 'valet'] as $tool) {
839+
$process = new Process([$tool, $command, '-v']);
840+
841+
try {
842+
$process->run();
843+
844+
if ($process->isSuccessful()) {
845+
return trim($process->getOutput());
846+
}
847+
} catch (ProcessStartFailedException) {
848+
}
849+
}
850+
851+
return false;
852+
}
853+
849854
/**
850855
* Run the given commands.
851856
*

0 commit comments

Comments
 (0)