mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
Drop need to pass sock to isolate command
This commit is contained in:
@@ -88,7 +88,7 @@ public function createConfigurationFiles($phpVersion = null)
|
|||||||
$contents = $this->files->get(__DIR__.'/../stubs/etc-phpfpm-valet.conf');
|
$contents = $this->files->get(__DIR__.'/../stubs/etc-phpfpm-valet.conf');
|
||||||
$contents = str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents);
|
$contents = str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents);
|
||||||
if ($phpVersion) {
|
if ($phpVersion) {
|
||||||
$contents = str_replace('valet.sock', $this->fpmSockName($phpVersion), $contents);
|
$contents = str_replace('valet.sock', self::fpmSockName($phpVersion), $contents);
|
||||||
}
|
}
|
||||||
$this->files->put($fpmConfigFile, $contents);
|
$this->files->put($fpmConfigFile, $contents);
|
||||||
|
|
||||||
@@ -195,12 +195,14 @@ public function isolateDirectoryToVersion($directory, $version)
|
|||||||
throw new DomainException("The [{$directory}] site could not be found in Valet's site list.");
|
throw new DomainException("The [{$directory}] site could not be found in Valet's site list.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$version = $this->validateRequestedVersion($version);
|
||||||
|
|
||||||
$this->brew->ensureInstalled($version, [], $this->taps);
|
$this->brew->ensureInstalled($version, [], $this->taps);
|
||||||
|
|
||||||
$oldCustomPhpVersion = $this->site->customPhpVersion($site); // Example output: "74"
|
$oldCustomPhpVersion = $this->site->customPhpVersion($site); // Example output: "74"
|
||||||
$this->createConfigurationFiles($version);
|
$this->createConfigurationFiles($version);
|
||||||
|
|
||||||
$this->site->isolate($site, $this->fpmSockName($version), $version);
|
$this->site->isolate($site, $version);
|
||||||
|
|
||||||
$this->stopIfUnused($oldCustomPhpVersion);
|
$this->stopIfUnused($oldCustomPhpVersion);
|
||||||
$this->restart($version);
|
$this->restart($version);
|
||||||
@@ -342,7 +344,7 @@ public function validateRequestedVersion($version)
|
|||||||
* @param string|null $phpVersion
|
* @param string|null $phpVersion
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function fpmSockName($phpVersion = null)
|
public static function fpmSockName($phpVersion = null)
|
||||||
{
|
{
|
||||||
$versionInteger = preg_replace('~[^\d]~', '', $phpVersion);
|
$versionInteger = preg_replace('~[^\d]~', '', $phpVersion);
|
||||||
|
|
||||||
@@ -373,12 +375,12 @@ public function updateConfigurationForGlobalUpdate($newPhpVersion, $oldPhpVersio
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($content, $this->fpmSockName($newPhpVersion)) !== false) {
|
if (strpos($content, self::fpmSockName($newPhpVersion)) !== false) {
|
||||||
info(sprintf('Updating site %s to keep using version: %s', $file, $newPhpVersion));
|
info(sprintf('Updating site %s to keep using version: %s', $file, $newPhpVersion));
|
||||||
$this->files->put(VALET_HOME_PATH.'/Nginx/'.$file, str_replace($this->fpmSockName($newPhpVersion), 'valet.sock', $content));
|
$this->files->put(VALET_HOME_PATH.'/Nginx/'.$file, str_replace(self::fpmSockName($newPhpVersion), 'valet.sock', $content));
|
||||||
} elseif (strpos($content, 'valet.sock') !== false) {
|
} elseif (strpos($content, 'valet.sock') !== false) {
|
||||||
info(sprintf('Updating site %s to keep using version: %s', $file, $oldPhpVersion));
|
info(sprintf('Updating site %s to keep using version: %s', $file, $oldPhpVersion));
|
||||||
$this->files->put(VALET_HOME_PATH.'/Nginx/'.$file, str_replace('valet.sock', $this->fpmSockName($oldPhpVersion), $content));
|
$this->files->put(VALET_HOME_PATH.'/Nginx/'.$file, str_replace('valet.sock', self::fpmSockName($oldPhpVersion), $content));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -392,7 +394,7 @@ public function updateConfigurationForGlobalUpdate($newPhpVersion, $oldPhpVersio
|
|||||||
public function utilizedPhpVersions()
|
public function utilizedPhpVersions()
|
||||||
{
|
{
|
||||||
$fpmSockFiles = $this->brew->supportedPhpVersions()->map(function ($version) {
|
$fpmSockFiles = $this->brew->supportedPhpVersions()->map(function ($version) {
|
||||||
return $this->fpmSockName($this->normalizePhpVersion($version));
|
return self::fpmSockName($this->normalizePhpVersion($version));
|
||||||
})->unique();
|
})->unique();
|
||||||
|
|
||||||
return collect($this->files->scandir(VALET_HOME_PATH.'/Nginx'))
|
return collect($this->files->scandir(VALET_HOME_PATH.'/Nginx'))
|
||||||
|
|||||||
@@ -697,15 +697,17 @@ public function buildSecureNginxServer($url, $siteConf = null)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the Nginx server configuration for the given Valet site.
|
* Create new nginx config or modify existing nginx config to isolate this site
|
||||||
|
* to a custom version of PHP.
|
||||||
*
|
*
|
||||||
* @param string $valetSite
|
* @param string $valetSite
|
||||||
* @param string $fpmSockName
|
|
||||||
* @param string $phpVersion
|
* @param string $phpVersion
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function isolate($valetSite, $fpmSockName, $phpVersion)
|
public function isolate($valetSite, $phpVersion)
|
||||||
{
|
{
|
||||||
|
$fpmSockName = PhpFpm::fpmSockName($phpVersion);
|
||||||
|
|
||||||
if ($this->files->exists($this->nginxPath($valetSite))) {
|
if ($this->files->exists($this->nginxPath($valetSite))) {
|
||||||
// Modify the existing config if it exists (likely because it's secured)
|
// Modify the existing config if it exists (likely because it's secured)
|
||||||
$siteConf = $this->files->get($this->nginxPath($valetSite));
|
$siteConf = $this->files->get($this->nginxPath($valetSite));
|
||||||
@@ -769,7 +771,7 @@ public function unsecure($url)
|
|||||||
|
|
||||||
// If the user had isolated the PHP version for this site, swap out .sock file
|
// If the user had isolated the PHP version for this site, swap out .sock file
|
||||||
if ($phpVersion) {
|
if ($phpVersion) {
|
||||||
$this->isolate($url, "valet{$phpVersion}.sock", $phpVersion);
|
$this->isolate($url, $phpVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ public function test_isolate_will_isolate_a_site()
|
|||||||
// $brewMock->shouldReceive('linkedPhp')->once();
|
// $brewMock->shouldReceive('linkedPhp')->once();
|
||||||
|
|
||||||
$siteMock->shouldReceive('getSiteUrl')->with('test')->andReturn('test.test');
|
$siteMock->shouldReceive('getSiteUrl')->with('test')->andReturn('test.test');
|
||||||
$siteMock->shouldReceive('isolate')->withArgs(['test.test', 'valet72.sock', 'php@7.2']);
|
$siteMock->shouldReceive('isolate')->withArgs(['test.test', 'php@7.2']);
|
||||||
$siteMock->shouldReceive('customPhpVersion')->with('test.test')->andReturn('72');
|
$siteMock->shouldReceive('customPhpVersion')->with('test.test')->andReturn('72');
|
||||||
|
|
||||||
$phpFpmMock->shouldReceive('stopIfUnused')->with('72')->once();
|
$phpFpmMock->shouldReceive('stopIfUnused')->with('72')->once();
|
||||||
|
|||||||
@@ -630,7 +630,7 @@ public function test_isolation_will_persist_when_removing_ssl_certificate()
|
|||||||
|
|
||||||
// If a site has an isolated PHP version, there should still be a custom nginx site config
|
// If a site has an isolated PHP version, there should still be a custom nginx site config
|
||||||
$siteMock->shouldReceive('customPhpVersion')->with('site1.test')->andReturn('73')->once();
|
$siteMock->shouldReceive('customPhpVersion')->with('site1.test')->andReturn('73')->once();
|
||||||
$siteMock->shouldReceive('isolate')->withArgs(['site1.test', 'valet73.sock', '73'])->once();
|
$siteMock->shouldReceive('isolate')->withArgs(['site1.test', '73'])->once();
|
||||||
resolve(Site::class)->unsecure('site1.test');
|
resolve(Site::class)->unsecure('site1.test');
|
||||||
|
|
||||||
// If a site doesn't have an isolated PHP version, there should no longer be a custom nginx site config
|
// If a site doesn't have an isolated PHP version, there should no longer be a custom nginx site config
|
||||||
@@ -668,7 +668,7 @@ public function test_can_install_nginx_site_config_for_specific_php_version()
|
|||||||
'# Valet isolated PHP version : php@8.0'.PHP_EOL.'server { fastcgi_pass: valet80.sock }',
|
'# Valet isolated PHP version : php@8.0'.PHP_EOL.'server { fastcgi_pass: valet80.sock }',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$siteMock->isolate('site1.test', 'valet80.sock', 'php@8.0');
|
$siteMock->isolate('site1.test', 'php@8.0');
|
||||||
|
|
||||||
// When no Nginx file exists, it will create a new config file from the template
|
// When no Nginx file exists, it will create a new config file from the template
|
||||||
$files->shouldReceive('exists')->once()->with($siteMock->nginxPath('site2.test'))->andReturn(false);
|
$files->shouldReceive('exists')->once()->with($siteMock->nginxPath('site2.test'))->andReturn(false);
|
||||||
@@ -688,7 +688,7 @@ public function test_can_install_nginx_site_config_for_specific_php_version()
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$siteMock->isolate('site2.test', 'valet80.sock', 'php@8.0');
|
$siteMock->isolate('site2.test', 'php@8.0');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_removes_isolation()
|
public function test_it_removes_isolation()
|
||||||
|
|||||||
Reference in New Issue
Block a user