mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 16:40:05 +01:00
* Extract basic driver with public/ from basic driver, and simplify both * Apply fixes from StyleCI * Set HTTP_HOST in BaseDriverTest * Move server helpers to their own file; add type hints * Update drivers location and loading - Extract much of server.php into a `Server` class - Move all but the Laravel and Basic drivers into a subfolder - Load all but the Laravel and Basic drivers via glob - Add `beforeLoading` hook to simplify the `frontControllerPath` method for some drivers * Apply fixes from StyleCI * Add additional notes to upgrade.md * Apply fixes from StyleCI * Require PHP 8.0 * Add type hints and return type hints to Brew * Apply fixes from StyleCI * Add type hints and return type hints to CommandLine * Add type hints and return type hints to Configuration * Add type hints and return type hints to Diagnose * Apply fixes from StyleCI * Add type hints and return type hints to DnsMasq * Add type hints and return hints to Filesystem * Add type hints and return types to Nginx * Add type hints and return types to ngrok * Add type hints and return types to PhpFpm * Apply fixes from StyleCI * Add type hints and return types to Site and Valet * Apply fixes from StyleCI * Require passing a version number to isolate command * Apply fixes from StyleCI * Bump compat to php 8; add type hints and return types to helpers * Apply fixes from StyleCI * Use constructor promotion * Apply fixes from StyleCI * Write tests for Server.php * Apply fixes from StyleCI * Move upgrade calls into Upgrader class, and add upgrade to check for old custom drivers * Apply fixes from StyleCI * Replace some \n with PHP_EOL; move custom drivers into Custom namespace * Apply fixes from StyleCI * Add doc blocks * Clean up NullWriter; drop legacy config check * Allow null response from frontControllerPath * Apply fixes from StyleCI * Drop exits, fix 404 path * Better handle new installations * Apply fixes from StyleCI * Drop extensions * Clean up DX for fetch-share-url * Apply fixes from StyleCI * Fix site::unlink method signature and docblock * Tweak the wording for the which command * Support isolated sites running PHP 7.4 * Add a bunch more CLI command tests (#1332) * Wip some cli tests * Apply fixes from StyleCI * Test parked command * Test forget command * Update Filesystem::rmDirAndContents to respect symlinks * Wip cli commands * Apply fixes from StyleCI * Test link command, unlink command, and secure command * Apply fixes from StyleCI * Add tests for unsecure, unsecure --all, secured commands Add placeholders for the remaining CLI commands Add nginx::restart to unsecure --all command Co-authored-by: StyleCI Bot <bot@styleci.io> * Drop old config migrations * Add status command (#1329) * Build the foundation of a status command * Apply fixes from StyleCI * Wip testing status command * Apply fixes from StyleCI * Fix status test * Apply fixes from StyleCI * Fix race condition in creating test config file * Apply fixes from StyleCI * Reset container for each test * Differentiate response code based on success or failure of status command * Apply fixes from StyleCI * Add the ability to test if a Brew service is running * Apply fixes from StyleCI * Check for more services running in status command * Apply fixes from StyleCI * Test Status * Apply fixes from StyleCI * Drop Yoast from base application test case Co-authored-by: StyleCI Bot <bot@styleci.io> * Test most of the remaining CLI commands * Test set tld command * Test set loopback command * Test proxy, unproxy, and proxies commands * Apply fixes from StyleCI * Test which command * Test diagnose command * Test directory-listing and which-php commands * Text isolate and unisolate and isolated commands * Apply fixes from StyleCI * Test trust command * Apply fixes from StyleCI * Test on-latest-version command * Move uninstall text to a class, and tweak text and presentation * Apply fixes from StyleCI * Test use command * Test stop command * Test start command * Test restart command Co-authored-by: StyleCI Bot <bot@styleci.io> * Drop unnecessary doc blocks (#1339) * Drop unnecessary doc blocks * Apply fixes from StyleCI Co-authored-by: StyleCI Bot <bot@styleci.io> * Tweak status output and install output * Add debug instructions to valet status, expand "valet installed" status check * Drop extensions directory * Apply fixes from StyleCI * Remove more docblocks * Upgrade ngrok to 3.1.0 * Test force uninstall command * Test log command * Drop copying Ngrok share to clipboard; add first steps of Expose code * Add logic paths for Expose vs. ngrok and the share-tool config * Apply fixes from StyleCI * Take the first steps of manually installing ngrok and expose when needed * Apply fixes from StyleCI * Next steps Brew-installed ngrok * Apply fixes from StyleCI * Add class to represent Composer; continue ngrok + expose updates * Apply fixes from StyleCI * Add ensureInstalled() method to Expose and installOrFail() to Composer * Apply fixes from StyleCI * Require global PHP 8+ to install * Exit if invalid domain is passed to valet share * Update Composer dependencies to use Illuminate/Container * Drop the idea of passing a custom domain to valet share Co-authored-by: StyleCI Bot <bot@styleci.io>
160 lines
4.7 KiB
PHP
160 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Valet;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Symfony\Component\Console\Helper\ProgressBar;
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
|
|
class Diagnose
|
|
{
|
|
public $commands = [
|
|
'sw_vers',
|
|
'valet --version',
|
|
'cat ~/.config/valet/config.json',
|
|
'cat ~/.composer/composer.json',
|
|
'composer global diagnose',
|
|
'composer global outdated',
|
|
'ls -al /etc/sudoers.d/',
|
|
'brew update > /dev/null 2>&1',
|
|
'brew config',
|
|
'brew services list',
|
|
'brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"',
|
|
'brew outdated',
|
|
'brew tap',
|
|
'php -v',
|
|
'which -a php',
|
|
'php --ini',
|
|
'nginx -v',
|
|
'curl --version',
|
|
'php --ri curl',
|
|
BREW_PREFIX.'/bin/ngrok version',
|
|
'ls -al ~/.ngrok2',
|
|
'brew info nginx',
|
|
'brew info php',
|
|
'brew info openssl',
|
|
'openssl version -a',
|
|
'openssl ciphers',
|
|
'sudo nginx -t',
|
|
'which -a php-fpm',
|
|
BREW_PREFIX.'/opt/php/sbin/php-fpm -v',
|
|
'sudo '.BREW_PREFIX.'/opt/php/sbin/php-fpm -y '.PHP_SYSCONFDIR.'/php-fpm.conf --test',
|
|
'ls -al ~/Library/LaunchAgents | grep homebrew',
|
|
'ls -al /Library/LaunchAgents | grep homebrew',
|
|
'ls -al /Library/LaunchDaemons | grep homebrew',
|
|
'ls -al /Library/LaunchDaemons | grep "com.laravel.valet."',
|
|
'ls -aln /etc/resolv.conf',
|
|
'cat /etc/resolv.conf',
|
|
'ifconfig lo0',
|
|
'sh -c \'echo "------\n'.BREW_PREFIX.'/etc/nginx/valet/valet.conf\n---\n"; cat '.BREW_PREFIX.'/etc/nginx/valet/valet.conf | grep -n "# valet loopback"; echo "\n------\n"\'',
|
|
'sh -c \'for file in ~/.config/valet/dnsmasq.d/*; do echo "------\n~/.config/valet/dnsmasq.d/$(basename $file)\n---\n"; cat $file; echo "\n------\n"; done\'',
|
|
'sh -c \'for file in ~/.config/valet/nginx/*; do echo "------\n~/.config/valet/nginx/$(basename $file)\n---\n"; cat $file | grep -n "# valet loopback"; echo "\n------\n"; done\'',
|
|
];
|
|
|
|
public $print;
|
|
public $progressBar;
|
|
|
|
public function __construct(public CommandLine $cli, public Filesystem $files)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Run diagnostics.
|
|
*/
|
|
public function run(bool $print, bool $plainText): void
|
|
{
|
|
$this->print = $print;
|
|
|
|
$this->beforeRun();
|
|
|
|
$results = collect($this->commands)->map(function ($command) {
|
|
$this->beforeCommand($command);
|
|
|
|
$output = $this->runCommand($command);
|
|
|
|
if ($this->ignoreOutput($command)) {
|
|
return;
|
|
}
|
|
|
|
$this->afterCommand($command, $output);
|
|
|
|
return compact('command', 'output');
|
|
})->filter()->values();
|
|
|
|
$output = $this->format($results, $plainText);
|
|
|
|
$this->files->put('valet_diagnostics.txt', $output);
|
|
|
|
$this->cli->run('pbcopy < valet_diagnostics.txt');
|
|
|
|
$this->files->unlink('valet_diagnostics.txt');
|
|
|
|
$this->afterRun();
|
|
}
|
|
|
|
public function beforeRun(): void
|
|
{
|
|
if ($this->print) {
|
|
return;
|
|
}
|
|
|
|
$this->progressBar = new ProgressBar(new ConsoleOutput, count($this->commands));
|
|
|
|
$this->progressBar->start();
|
|
}
|
|
|
|
public function afterRun(): void
|
|
{
|
|
if ($this->progressBar) {
|
|
$this->progressBar->finish();
|
|
}
|
|
|
|
output('');
|
|
}
|
|
|
|
public function runCommand(string $command): string
|
|
{
|
|
return strpos($command, 'sudo ') === 0
|
|
? $this->cli->run($command)
|
|
: $this->cli->runAsUser($command);
|
|
}
|
|
|
|
public function beforeCommand(string $command): void
|
|
{
|
|
if ($this->print) {
|
|
info(PHP_EOL."$ $command");
|
|
}
|
|
}
|
|
|
|
public function afterCommand(string $command, string $output): void
|
|
{
|
|
if ($this->print) {
|
|
output(trim($output));
|
|
} else {
|
|
$this->progressBar->advance();
|
|
}
|
|
}
|
|
|
|
public function ignoreOutput(string $command): bool
|
|
{
|
|
return strpos($command, '> /dev/null 2>&1') !== false;
|
|
}
|
|
|
|
public function format(Collection $results, bool $plainText): string
|
|
{
|
|
return $results->map(function ($result) use ($plainText) {
|
|
$command = $result['command'];
|
|
$output = trim($result['output']);
|
|
|
|
if ($plainText) {
|
|
return implode(PHP_EOL, ["$ {$command}", $output]);
|
|
}
|
|
|
|
return sprintf(
|
|
'<details>%s<summary>%s</summary>%s<pre>%s</pre>%s</details>',
|
|
PHP_EOL, $command, PHP_EOL, $output, PHP_EOL
|
|
);
|
|
})->implode($plainText ? PHP_EOL.str_repeat('-', 20).PHP_EOL : PHP_EOL);
|
|
}
|
|
}
|