1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 08:30:07 +01:00

Add 'parked' command to show all sites which have been parked using valet park 'path'

This commit is contained in:
James Barnard
2019-10-02 13:31:06 +01:00
parent eb0f03869c
commit 9d4126856d
3 changed files with 187 additions and 1 deletions

View File

@@ -112,6 +112,32 @@ function links()
return $this->getLinks($this->sitesPath(), $certs);
}
/**
* Pretty print out all parked links in Valet
*
* @return \Illuminate\Support\Collection
*/
function parked()
{
$certsPath = VALET_HOME_PATH.'/Certificates';
$this->files->ensureDirExists($certsPath, user());
$certs = $this->getCertificates($certsPath);
$config = $this->config->read();
$parkedLinks = collect();
foreach ($config['paths'] as $path) {
if ($path === $this->sitesPath()) {
continue;
}
$parkedLinks = $parkedLinks->merge($this->getSites($path, $certs));
}
return $parkedLinks;
}
/**
* Get all certificates from config folder.
*
@@ -130,17 +156,39 @@ function getCertificates($path)
/**
* Get list of links and present them formatted.
* Use generic getSites which works for link and non link sites
*
* @param string $path
* @param \Illuminate\Support\Collection $certs
* @return \Illuminate\Support\Collection
*/
function getLinks($path, $certs)
{
return $this->getSites($path, $certs);
}
/**
* Get list of sites and return them formatted
* Will work for symlink and normal site paths
*
* @param $path
* @param $certs
*
* @return \Illuminate\Support\Collection
*/
function getSites($path, $certs)
{
$config = $this->config->read();
return collect($this->files->scandir($path))->mapWithKeys(function ($site) use ($path) {
return [$site => $this->files->readLink($path.'/'.$site)];
$sitePath = $path.'/'.$site;
if ($this->files->isLink($sitePath)) {
$realPath = $this->files->readLink($sitePath);
} else {
$realPath = $this->files->realpath($sitePath);
}
return [$site => $realPath];
})->map(function ($path, $site) use ($certs, $config) {
$secured = $certs->has($site);
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['tld'];