mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 08:40:09 +01:00
pretty print sites
This commit is contained in:
@@ -28,6 +28,7 @@ function install()
|
|||||||
$this->createSitesDirectory();
|
$this->createSitesDirectory();
|
||||||
$this->createExtensionsDirectory();
|
$this->createExtensionsDirectory();
|
||||||
$this->createLogDirectory();
|
$this->createLogDirectory();
|
||||||
|
$this->createCertificatesDirectory();
|
||||||
$this->writeBaseConfiguration();
|
$this->writeBaseConfiguration();
|
||||||
|
|
||||||
$this->files->chown($this->path(), user());
|
$this->files->chown($this->path(), user());
|
||||||
@@ -94,6 +95,16 @@ function createLogDirectory()
|
|||||||
$this->files->touch(VALET_HOME_PATH.'/Log/nginx-error.log');
|
$this->files->touch(VALET_HOME_PATH.'/Log/nginx-error.log');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the directory for SSL certificates.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function createCertificatesDirectory()
|
||||||
|
{
|
||||||
|
$this->files->ensureDirExists(VALET_HOME_PATH.'/Certificates', user());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the base, initial configuration for Valet.
|
* Write the base, initial configuration for Valet.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -59,6 +59,57 @@ function link($target, $link)
|
|||||||
return $linkPath.'/'.$link;
|
return $linkPath.'/'.$link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pretty print out all links in Valet.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
function links() {
|
||||||
|
$certsPath = VALET_HOME_PATH.'/Certificates';
|
||||||
|
|
||||||
|
$this->files->ensureDirExists($certsPath, user());
|
||||||
|
|
||||||
|
$certs = $this->getCertificates($certsPath);
|
||||||
|
|
||||||
|
return $this->getLinks(VALET_HOME_PATH.'/Sites', $certs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all certificates from config folder.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
function getCertificates(string $path)
|
||||||
|
{
|
||||||
|
return collect($this->files->scanDir($path))->filter(function ($value, $key) {
|
||||||
|
return ends_with($value, '.crt');
|
||||||
|
})->map(function ($cert) {
|
||||||
|
return substr($cert, 0, -8);
|
||||||
|
})->flip();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of links and present them formatted.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @param \Illuminate\Support\Collection $certs
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
function getLinks(string $path, \Illuminate\Support\Collection $certs)
|
||||||
|
{
|
||||||
|
$config = $this->config->read();
|
||||||
|
|
||||||
|
return collect($this->files->scanDir($path))->mapWithKeys(function ($site) use($path) {
|
||||||
|
return [$site => $this->files->readLink($path.'/'.$site)];
|
||||||
|
})->map(function ($path, $site) use($certs, $config) {
|
||||||
|
$secured = $certs->has($site);
|
||||||
|
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['domain'];
|
||||||
|
|
||||||
|
return [$site, $secured ? ' X': '', $url, $path];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlink the given symbolic link.
|
* Unlink the given symbolic link.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
use Symfony\Component\Console\Helper\Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the ~/.valet path as a constant.
|
* Define the ~/.valet path as a constant.
|
||||||
@@ -32,6 +34,22 @@ function warning($output)
|
|||||||
output('<fg=red>'.$output.'</>');
|
output('<fg=red>'.$output.'</>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output a table to the console.
|
||||||
|
*
|
||||||
|
* @param array $headers
|
||||||
|
* @param array $rows
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function table(array $headers = [], array $rows = [])
|
||||||
|
{
|
||||||
|
$table = new Table(new ConsoleOutput);
|
||||||
|
|
||||||
|
$table->setHeaders($headers)->setRows($rows);
|
||||||
|
|
||||||
|
$table->render();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the given text to the console.
|
* Output the given text to the console.
|
||||||
*
|
*
|
||||||
@@ -44,7 +62,7 @@ function output($output)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(new Symfony\Component\Console\Output\ConsoleOutput)->writeln($output);
|
(new ConsoleOutput)->writeln($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! function_exists('resolve')) {
|
if (! function_exists('resolve')) {
|
||||||
@@ -130,6 +148,24 @@ function tap($value, callable $callback)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('ends_with')) {
|
||||||
|
/**
|
||||||
|
* Determine if a given string ends with a given substring.
|
||||||
|
*
|
||||||
|
* @param string $haystack
|
||||||
|
* @param string|array $needles
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function ends_with($haystack, $needles) {
|
||||||
|
foreach ((array) $needles as $needle) {
|
||||||
|
if (substr($haystack, -strlen($needle)) === (string) $needle) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user
|
* Get the user
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -101,7 +101,9 @@
|
|||||||
* Display all of the registered symbolic links.
|
* Display all of the registered symbolic links.
|
||||||
*/
|
*/
|
||||||
$app->command('links', function () {
|
$app->command('links', function () {
|
||||||
passthru('ls -lA '.VALET_HOME_PATH.'/Sites');
|
$links = Site::links();
|
||||||
|
|
||||||
|
table(['Site', 'SSL', 'URL', 'Path'], $links->all());
|
||||||
})->descriptions('Display all of the registered Valet links');
|
})->descriptions('Display all of the registered Valet links');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user