Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Console\View\Components;
4
 
5
use Symfony\Component\Console\Output\OutputInterface;
6
use function Termwind\terminal;
7
use Throwable;
8
 
9
class Task extends Component
10
{
11
    /**
12
     * Renders the component using the given arguments.
13
     *
14
     * @param  string  $description
15
     * @param  (callable(): bool)|null  $task
16
     * @param  int  $verbosity
17
     * @return void
18
     */
19
    public function render($description, $task = null, $verbosity = OutputInterface::VERBOSITY_NORMAL)
20
    {
21
        $description = $this->mutate($description, [
22
            Mutators\EnsureDynamicContentIsHighlighted::class,
23
            Mutators\EnsureNoPunctuation::class,
24
            Mutators\EnsureRelativePaths::class,
25
        ]);
26
 
27
        $descriptionWidth = mb_strlen(preg_replace("/\<[\w=#\/\;,:.&,%?]+\>|\\e\[\d+m/", '$1', $description) ?? '');
28
 
29
        $this->output->write("  $description ", false, $verbosity);
30
 
31
        $startTime = microtime(true);
32
 
33
        $result = false;
34
 
35
        try {
36
            $result = ($task ?: fn () => true)();
37
        } catch (Throwable $e) {
38
            throw $e;
39
        } finally {
40
            $runTime = $task
41
                ? (' '.number_format((microtime(true) - $startTime) * 1000).'ms')
42
                : '';
43
 
44
            $runTimeWidth = mb_strlen($runTime);
45
            $width = min(terminal()->width(), 150);
46
            $dots = max($width - $descriptionWidth - $runTimeWidth - 10, 0);
47
 
48
            $this->output->write(str_repeat('<fg=gray>.</>', $dots), false, $verbosity);
49
            $this->output->write("<fg=gray>$runTime</>", false, $verbosity);
50
 
51
            $this->output->writeln(
52
                $result !== false ? ' <fg=green;options=bold>DONE</>' : ' <fg=red;options=bold>FAIL</>',
53
                $verbosity,
54
            );
55
        }
56
    }
57
}