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

Update version-4 to include #1361 #1365

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Bring #1361 into version-4
  • Loading branch information
mattstauffer committed Feb 11, 2023
commit c24ae199728bc52615791f0ceeb55a1539e8b532
46 changes: 26 additions & 20 deletions cli/Valet/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -1053,20 +1053,24 @@ public function replaceSockFile(string $siteConf, string $phpVersion): string
/**
* Get configuration items defined in .valetrc for a site.
*/
public function valetRc(string $siteName): array
public function valetRc(string $siteName, ?string $cwd = null): array
{
if ($site = $this->parked()->merge($this->links())->where('site', $siteName)->first()) {
if ($cwd) {
$path = $cwd.'/.valetrc';
} elseif ($site = $this->parked()->merge($this->links())->where('site', $siteName)->first()) {
$path = data_get($site, 'path').'/.valetrc';
} else {
return [];
}

if ($this->files->exists($path)) {
return collect(explode(PHP_EOL, trim($this->files->get($path))))->filter(function ($line) {
return str_contains($line, '=');
})->mapWithKeys(function ($item, $index) {
[$key, $value] = explode('=', $item);
if ($this->files->exists($path)) {
return collect(explode(PHP_EOL, trim($this->files->get($path))))->filter(function ($line) {
return str_contains($line, '=');
})->mapWithKeys(function ($item, $index) {
[$key, $value] = explode('=', $item);

return [strtolower($key) => $value];
})->all();
}
return [strtolower($key) => $value];
})->all();
}

return [];
Expand All @@ -1075,20 +1079,22 @@ public function valetRc(string $siteName): array
/**
* Get PHP version from .valetrc or .valetphprc for a site.
*/
public function phpRcVersion(string $siteName): ?string
public function phpRcVersion(string $siteName, ?string $cwd = null): ?string
{
if ($site = $this->parked()->merge($this->links())->where('site', $siteName)->first()) {
if ($cwd) {
$oldPath = $cwd.'/.valetphprc';
} elseif ($site = $this->parked()->merge($this->links())->where('site', $siteName)->first()) {
$oldPath = data_get($site, 'path').'/.valetphprc';
} else {
return null;
}

if ($this->files->exists($oldPath)) {
return PhpFpm::normalizePhpVersion(trim($this->files->get($oldPath)));
}

$valetRc = $this->valetRc($siteName);

return PhpFpm::normalizePhpVersion(data_get($valetRc, 'php'));
if ($this->files->exists($oldPath)) {
return PhpFpm::normalizePhpVersion(trim($this->files->get($oldPath)));
}

return null;
$valetRc = $this->valetRc($siteName, $cwd);

return PhpFpm::normalizePhpVersion(data_get($valetRc, 'php'));
}
}
4 changes: 2 additions & 2 deletions cli/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ function (ConsoleCommandEvent $event) {
$site = basename(getcwd());
$linkedVersion = Brew::linkedPhp();

if ($phpVersion = Site::phpRcVersion($site)) {
if ($phpVersion = Site::phpRcVersion($site, getcwd())) {
info("Found '{$site}/.valetrc' or '{$site}/.valetphprc' specifying version: {$phpVersion}");
} else {
$domain = $site.'.'.data_get(Configuration::read(), 'tld');
Expand Down Expand Up @@ -620,7 +620,7 @@ function (ConsoleCommandEvent $event) {
}

if (is_null($phpVersion)) {
if ($phpVersion = Site::phpRcVersion($site)) {
if ($phpVersion = Site::phpRcVersion($site, getcwd())) {
info("Found '{$site}/.valetrc' or '{$site}/.valetphprc' specifying version: {$phpVersion}");
} else {
info(PHP_EOL.'Please provide a version number. E.g.:');
Expand Down
1 change: 1 addition & 0 deletions tests/SiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ public function test_it_can_read_php_rc_version()
$this->assertEquals('php@8.0', $site->phpRcVersion('site-w-valetrc-1'));
$this->assertEquals('php@8.1', $site->phpRcVersion('site-w-valetrc-2'));
$this->assertEquals('php@8.2', $site->phpRcVersion('site-w-valetrc-3'));
$this->assertEquals('php@8.2', $site->phpRcVersion('blabla', __DIR__.'/fixtures/Parked/Sites/site-w-valetrc-3'));
}
}

Expand Down