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

Merge pull request #1365 from laravel/mes/update-1361

Update version-4 to include #1361
This commit is contained in:
Matt Stauffer
2023-02-10 20:37:37 -05:00
committed by GitHub
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'));
}
}

View File

@@ -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');
@@ -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.:');

View File

@@ -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'));
}
}