mirror of
https://github.com/laravel/valet.git
synced 2026-02-04 16:10:08 +01:00
Add command to list isolated sites
This commit is contained in:
@@ -177,4 +177,17 @@ public function uninstall()
|
|||||||
$this->brew->uninstallFormula('nginx nginx-full');
|
$this->brew->uninstallFormula('nginx nginx-full');
|
||||||
$this->cli->quietly('rm -rf '.BREW_PREFIX.'/etc/nginx '.BREW_PREFIX.'/var/log/nginx');
|
$this->cli->quietly('rm -rf '.BREW_PREFIX.'/etc/nginx '.BREW_PREFIX.'/var/log/nginx');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of all sites with explicit Nginx configurations
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public function configuredSites()
|
||||||
|
{
|
||||||
|
return collect($this->files->scandir(VALET_HOME_PATH.'/Nginx'))
|
||||||
|
->reject(function ($file) {
|
||||||
|
return starts_with($file, '.');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,6 +243,22 @@ public function unIsolateDirectory($directory)
|
|||||||
info(sprintf('The site [%s] is now using the default PHP version.', $site));
|
info(sprintf('The site [%s] is now using the default PHP version.', $site));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all directories with PHP isolation configured.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public function isolatedDirectories()
|
||||||
|
{
|
||||||
|
$configuredSites = $this->nginx->configuredSites();
|
||||||
|
|
||||||
|
return $configuredSites->filter(function ($item) {
|
||||||
|
return str_contains($this->files->get(VALET_HOME_PATH.'/Nginx/'.$item), 'Valet isolated PHP version');
|
||||||
|
})->map(function ($item) {
|
||||||
|
return ['url' => $item];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use a specific version of PHP globally.
|
* Use a specific version of PHP globally.
|
||||||
*
|
*
|
||||||
@@ -366,11 +382,7 @@ public function utilizedPhpVersions()
|
|||||||
return self::fpmSockName($this->normalizePhpVersion($version));
|
return self::fpmSockName($this->normalizePhpVersion($version));
|
||||||
})->unique();
|
})->unique();
|
||||||
|
|
||||||
return collect($this->files->scandir(VALET_HOME_PATH.'/Nginx'))
|
return $this->nginx->configuredSites()->map(function ($file) use ($fpmSockFiles) {
|
||||||
->reject(function ($file) {
|
|
||||||
return starts_with($file, '.');
|
|
||||||
})
|
|
||||||
->map(function ($file) use ($fpmSockFiles) {
|
|
||||||
$content = $this->files->get(VALET_HOME_PATH.'/Nginx/'.$file);
|
$content = $this->files->get(VALET_HOME_PATH.'/Nginx/'.$file);
|
||||||
|
|
||||||
// Get the normalized PHP version for this config file, if it's defined
|
// Get the normalized PHP version for this config file, if it's defined
|
||||||
|
|||||||
@@ -528,7 +528,16 @@
|
|||||||
*/
|
*/
|
||||||
$app->command('unisolate', function () {
|
$app->command('unisolate', function () {
|
||||||
PhpFpm::unIsolateDirectory(basename(getcwd()));
|
PhpFpm::unIsolateDirectory(basename(getcwd()));
|
||||||
})->descriptions('Stop customizing the version of PHP used by valet to serve the current working directory');
|
})->descriptions('Stop customizing the version of PHP used by Valet to serve the current working directory');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List isolated sites
|
||||||
|
*/
|
||||||
|
$app->command('isolated', function () {
|
||||||
|
$sites = PhpFpm::isolatedDirectories();
|
||||||
|
|
||||||
|
table(['Path'], $sites->all());
|
||||||
|
})->descriptions('List all sites using isolated versions of PHP.');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tail log file.
|
* Tail log file.
|
||||||
|
|||||||
@@ -86,4 +86,26 @@ public function test_install_nginx_directories_rewrites_secure_nginx_files()
|
|||||||
|
|
||||||
$site->shouldHaveReceived('resecureForNewConfiguration', [$data, $data]);
|
$site->shouldHaveReceived('resecureForNewConfiguration', [$data, $data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_gets_configured_sites()
|
||||||
|
{
|
||||||
|
$files = Mockery::mock(Filesystem::class);
|
||||||
|
|
||||||
|
$files->shouldReceive('scandir')
|
||||||
|
->once()
|
||||||
|
->with(VALET_HOME_PATH . '/Nginx')
|
||||||
|
->andReturn(['.gitkeep', 'isolated-site-71.test', 'isolated-site-72.test', 'isolated-site-73.test']);
|
||||||
|
|
||||||
|
swap(Filesystem::class, $files);
|
||||||
|
swap(Configuration::class, $config = Mockery::spy(Configuration::class, ['read' => ['tld' => 'test', 'loopback' => VALET_LOOPBACK]]));
|
||||||
|
swap(Site::class, Mockery::mock(Site::class));
|
||||||
|
|
||||||
|
$nginx = resolve(Nginx::class);
|
||||||
|
$output = $nginx->configuredSites();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
['isolated-site-71.test', 'isolated-site-72.test', 'isolated-site-73.test'],
|
||||||
|
$output->values()->all()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public function test_utilized_php_versions()
|
|||||||
{
|
{
|
||||||
$fileSystemMock = Mockery::mock(Filesystem::class);
|
$fileSystemMock = Mockery::mock(Filesystem::class);
|
||||||
$brewMock = Mockery::mock(Brew::class);
|
$brewMock = Mockery::mock(Brew::class);
|
||||||
|
$nginxMock = Mockery::mock(Nginx::class);
|
||||||
|
|
||||||
$phpFpmMock = Mockery::mock(PhpFpm::class, [
|
$phpFpmMock = Mockery::mock(PhpFpm::class, [
|
||||||
$brewMock,
|
$brewMock,
|
||||||
@@ -71,7 +72,7 @@ public function test_utilized_php_versions()
|
|||||||
$fileSystemMock,
|
$fileSystemMock,
|
||||||
resolve(Configuration::class),
|
resolve(Configuration::class),
|
||||||
Mockery::mock(Site::class),
|
Mockery::mock(Site::class),
|
||||||
Mockery::mock(Nginx::class),
|
$nginxMock,
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
swap(PhpFpm::class, $phpFpmMock);
|
swap(PhpFpm::class, $phpFpmMock);
|
||||||
@@ -85,12 +86,9 @@ public function test_utilized_php_versions()
|
|||||||
|
|
||||||
$brewMock->shouldReceive('getLinkedPhpFormula')->andReturn('php@7.3');
|
$brewMock->shouldReceive('getLinkedPhpFormula')->andReturn('php@7.3');
|
||||||
|
|
||||||
$fileSystemMock->shouldReceive('scandir')
|
$nginxMock->shouldReceive('configuredSites')
|
||||||
->once()
|
->once()
|
||||||
->with(VALET_HOME_PATH.'/Nginx')
|
->andReturn(collect(['isolated-site-71.test', 'isolated-site-72.test', 'isolated-site-73.test']));
|
||||||
->andReturn(['.gitkeep', 'isolated-site-71.test', 'isolated-site-72.test', 'isolated-site-73.test']);
|
|
||||||
|
|
||||||
$fileSystemMock->shouldNotReceive('get')->with(VALET_HOME_PATH.'/Nginx/.gitkeep');
|
|
||||||
|
|
||||||
$sites = [
|
$sites = [
|
||||||
[
|
[
|
||||||
@@ -114,6 +112,11 @@ public function test_utilized_php_versions()
|
|||||||
$this->assertEquals(['php@7.1', 'php@7.2', 'php@7.3'], resolve(PhpFpm::class)->utilizedPhpVersions());
|
$this->assertEquals(['php@7.1', 'php@7.2', 'php@7.3'], resolve(PhpFpm::class)->utilizedPhpVersions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_lists_isolated_directories()
|
||||||
|
{
|
||||||
|
$this->markTestIncomplete('@todo');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_stop_unused_php_versions()
|
public function test_stop_unused_php_versions()
|
||||||
{
|
{
|
||||||
$brewMock = Mockery::mock(Brew::class);
|
$brewMock = Mockery::mock(Brew::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user