芝麻web文件管理V1.00
编辑当前文件:/home/rejoandoctor/medicine.joruridoctor.com/vendor/laravel/pail/src/Printers/CliPrinter.php
truncateClassOrType($messageLogged->classOrType()); $color = $messageLogged->color(); $message = $this->truncateMessage($messageLogged->message()); $date = $this->output->isVerbose() ? $messageLogged->date() : $messageLogged->time(); $fileHtml = $this->fileHtml($messageLogged->file(), $classOrType); $messageHtml = $this->messageHtml($message); $optionsHtml = $this->optionsHtml($messageLogged); $traceHtml = $this->traceHtml($messageLogged); $messageClasses = $this->output->isVerbose() ? '' : 'truncate'; $endingTopRight = $this->output->isVerbose() ? '' : '┐'; $endingMiddle = $this->output->isVerbose() ? '' : '│'; $endingBottomRight = $this->output->isVerbose() ? '' : '┘'; renderUsing($this->output); render(<<
┌
$date
$classOrType
$fileHtml
$endingTopRight
│
$messageHtml
$endingMiddle
$traceHtml
└
$optionsHtml
$endingBottomRight
HTML); } /** * Creates a new instance printer instance. */ public function __construct(protected OutputInterface $output, protected string $basePath) { // } /** * Gets the file html. */ protected function fileHtml(?string $file, string $classOrType): ?string { if (is_null($file)) { return null; } if ($_ENV['PAIL_TESTS'] ?? false) { $file = $this->basePath.'/app/MyClass.php:12'; } $file = str_replace($this->basePath.'/', '', $file); if (! $this->output->isVerbose()) { $file = Str::of($file) ->explode('/') ->when( fn (Collection $file) => $file->count() > 4, fn (Collection $file) => $file->take(2)->merge( ['…', (string) $file->last()], ), )->implode('/'); $fileSize = max(0, min(terminal()->width() - strlen($classOrType) - 16, 145)); if (strlen($file) > $fileSize) { $file = mb_substr($file, 0, $fileSize).'…'; } } if ($file === '…') { return null; } $file = str_replace('……', '…', $file); return << $file HTML; } /** * Gets the message html. */ protected function messageHtml(string $message): string { if (empty($message)) { return '
No message.
'; } $message = htmlspecialchars($message); return "
$message
"; } /** * Truncates the class or type, if needed. */ protected function truncateClassOrType(string $classOrType): string { if ($this->output->isVerbose()) { return $classOrType; } return Str::of($classOrType) ->explode('\\') ->when( fn (Collection $classOrType) => $classOrType->count() > 4, fn (Collection $classOrType) => $classOrType->take(2)->merge( ['…', (string) $classOrType->last()] ), )->implode('\\'); } /** * Truncates the message, if needed. */ protected function truncateMessage(string $message): string { if (! $this->output->isVerbose()) { $messageSize = max(0, min(terminal()->width() - 5, 145)); if (strlen($message) > $messageSize) { $message = mb_substr($message, 0, $messageSize).'…'; } } return $message; } /** * Gets the options html. */ public function optionsHtml(MessageLogged $messageLogged): string { $origin = $messageLogged->origin(); if ($origin instanceof Http) { if (str_starts_with($path = $origin->path, '/') === false) { $path = '/'.$origin->path; } $options = [ strtoupper($origin->method) => $path, 'Auth ID' => $origin->authId ? ($origin->authId.($origin->authEmail ? " ({$origin->authEmail})" : '')) : 'guest', ]; } elseif ($origin instanceof Queue) { $options = [ $origin->command ? "artisan {$origin->command}" : null, $origin->queue, $origin->job, ]; } else { $options = [ $origin->command ? "artisan {$origin->command}" : 'artisan', ]; } return collect($options)->merge( $messageLogged->context() // @phpstan-ignore argument.type )->reject(fn (mixed $value, string|int $key) => is_int($key) && is_null($value)) ->map(fn (mixed $value) => is_string($value) ? $value : var_export($value, true)) ->map(fn (string $value) => htmlspecialchars($value)) ->map(fn (string $value, string|int $key) => is_string($key) ? "$key: $value" : $value) ->map(fn (string $value) => "
$value
") ->implode(' • '); } /** * Gets the trace html. */ public function traceHtml(MessageLogged $messageLogged): string { if (! $this->output->isVeryVerbose()) { return ''; } $trace = $messageLogged->trace(); if ($_ENV['PAIL_TESTS'] ?? false) { $trace = [ [ 'line' => 12, 'file' => $this->basePath.'/app/MyClass.php', ], [ 'line' => 34, 'file' => $this->basePath.'/app/MyClass.php', ], ]; } if (is_null($trace)) { return ''; } return collect($trace) ->map(function (array $frame, int $index) { $number = $index + 1; [ 'line' => $line, 'file' => $file, ] = $frame; $file = str_replace($this->basePath.'/', '', $file); $remainingTraces = ''; if (! $this->output->isVerbose()) { $file = (string) Str::of($file) ->explode('/') ->when( fn (Collection $file) => $file->count() > 4, fn (Collection $file) => $file->take(2)->merge( ['…', (string) $file->last()], ), )->implode('/'); } return <<
│
$number. $file:$line $remainingTraces
HTML; })->implode(''); } }