Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fixes issue if there is no herd or valet installed #343

Merged
merged 3 commits into from
May 31, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -760,17 +761,7 @@ protected function generateAppUrl($name)
*/
protected function getTld()
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, 'tld', '-v']);

$process->run();

if ($process->isSuccessful()) {
return trim($process->getOutput());
}
}

return 'test';
return $this->runOnValetOrHerd('tld') ?? 'test';
}

/**
Expand All @@ -792,15 +783,29 @@ protected function canResolveHostname($hostname)
*/
protected function isParked(string $directory)
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, 'paths', '-v']);
$output = $this->runOnValetOrHerd('paths');

return $output !== false ? in_array(dirname($directory), json_decode($output)) : false;
}

$process->run();
/**
* Runs the given command on "herd" or "valet" cli.
*
* @param string $command
* @return string|bool
*/
protected function runOnValetOrHerd(string $command)
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, $command, '-v']);

if ($process->isSuccessful()) {
$output = json_decode(trim($process->getOutput()));
try {
$process->run();

return in_array(dirname($directory), $output);
if ($process->isSuccessful()) {
return trim($process->getOutput());
}
} catch (ProcessStartFailedException) {
}
xiCO2k marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down