1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +01:00

Bring #1361 into version-4

This commit is contained in:
Matt Stauffer
2023-02-10 20:09:28 -05:00
parent 4af660e0f8
commit c24ae19972
3 changed files with 30 additions and 23 deletions

View File

@@ -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 [];
@@ -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';
if ($this->files->exists($oldPath)) {
return PhpFpm::normalizePhpVersion(trim($this->files->get($oldPath)));
}
$valetRc = $this->valetRc($siteName);
return PhpFpm::normalizePhpVersion(data_get($valetRc, 'php'));
} else {
return null;
}
return null;
if ($this->files->exists($oldPath)) {
return PhpFpm::normalizePhpVersion(trim($this->files->get($oldPath)));
}
$valetRc = $this->valetRc($siteName, $cwd);
return PhpFpm::normalizePhpVersion(data_get($valetRc, 'php'));
}
}