1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 16:50:09 +01:00

Update phpRc reader to check cwd before checking config, if cwd specified

This commit is contained in:
Matt Stauffer
2023-02-07 18:40:18 -05:00
parent c3a2b0be24
commit 73b5e987e2
3 changed files with 21 additions and 6 deletions

View File

@@ -1178,16 +1178,27 @@ public function replaceSockFile($siteConf, $phpVersion)
* Get PHP version from .valetphprc for a site. * Get PHP version from .valetphprc for a site.
* *
* @param string $site * @param string $site
* @param string $cwd In contexts in which a current working directory has been passed,
* the cwd, which is prioritized over looking for the site's information
* from the config.
* @return string|null * @return string|null
*/ */
public function phpRcVersion($site) public function phpRcVersion($site, $cwd = null)
{ {
if ($cwd) {
$path = $cwd.'/.valetphprc';
}
if ($site = $this->parked()->merge($this->links())->where('site', $site)->first()) { if ($site = $this->parked()->merge($this->links())->where('site', $site)->first()) {
$path = data_get($site, 'path').'/.valetphprc'; $path = data_get($site, 'path').'/.valetphprc';
}
if ($this->files->exists($path)) { if (! isset($path)) {
return PhpFpm::normalizePhpVersion(trim($this->files->get($path))); return;
} }
if ($this->files->exists($path)) {
return PhpFpm::normalizePhpVersion(trim($this->files->get($path)));
} }
} }
} }

View File

@@ -541,7 +541,7 @@ function (ConsoleCommandEvent $event) {
$site = basename(getcwd()); $site = basename(getcwd());
$linkedVersion = Brew::linkedPhp(); $linkedVersion = Brew::linkedPhp();
if ($phpVersion = Site::phpRcVersion($site)) { if ($phpVersion = Site::phpRcVersion($site, getcwd())) {
info("Found '{$site}/.valetphprc' specifying version: {$phpVersion}"); info("Found '{$site}/.valetphprc' specifying version: {$phpVersion}");
} else { } else {
$domain = $site.'.'.data_get(Configuration::read(), 'tld'); $domain = $site.'.'.data_get(Configuration::read(), 'tld');

View File

@@ -945,9 +945,13 @@ public function test_it_can_read_php_rc_version()
$files->shouldReceive('exists')->with('/Users/name/some-other-directory/site2/.valetphprc')->andReturn(true); $files->shouldReceive('exists')->with('/Users/name/some-other-directory/site2/.valetphprc')->andReturn(true);
$files->shouldReceive('get')->with('/Users/name/some-other-directory/site2/.valetphprc')->andReturn('php@8.0'); $files->shouldReceive('get')->with('/Users/name/some-other-directory/site2/.valetphprc')->andReturn('php@8.0');
$files->shouldReceive('exists')->with('/tmp/cwd-site/.valetphprc')->andReturn(true);
$files->shouldReceive('get')->with('/tmp/cwd-site/.valetphprc')->andReturn('php@8.2');
$this->assertEquals('php@8.1', $siteMock->phpRcVersion('site1')); $this->assertEquals('php@8.1', $siteMock->phpRcVersion('site1'));
$this->assertEquals('php@8.0', $siteMock->phpRcVersion('site2')); $this->assertEquals('php@8.0', $siteMock->phpRcVersion('site2'));
$this->assertEquals(null, $siteMock->phpRcVersion('site3')); // Site doesn't exists $this->assertEquals('php@8.2', $siteMock->phpRcVersion('blabla', '/tmp/cwd-site'));
$this->assertEquals(null, $siteMock->phpRcVersion('site3')); // Site doesn't exist
} }
} }