1 | <?php |
||
16 | class Informer |
||
17 | { |
||
18 | /** |
||
19 | * @var OutputWatcher |
||
20 | */ |
||
21 | private $output; |
||
22 | |||
23 | /** |
||
24 | * @var int|double |
||
25 | */ |
||
26 | private $startTime; |
||
27 | |||
28 | 7 | public function __construct(OutputWatcher $output) |
|
32 | |||
33 | 4 | public function startTask(Task $task) |
|
44 | |||
45 | /** |
||
46 | * Print task was ok. |
||
47 | */ |
||
48 | 5 | public function endTask(Task $task) |
|
49 | { |
||
50 | 5 | if ($task->isShallow()) { |
|
51 | return; |
||
52 | } |
||
53 | |||
54 | 5 | $endTime = round(microtime(true) * 1000); |
|
55 | 5 | $millis = $endTime - $this->startTime; |
|
56 | 5 | $seconds = floor($millis / 1000); |
|
57 | 5 | $millis = $millis - $seconds * 1000; |
|
58 | 5 | $taskTime = ($seconds > 0 ? "{$seconds}s " : "") . "{$millis}ms"; |
|
59 | |||
60 | $shouldReplaceTaskMark = |
||
61 | 5 | $this->output->isDecorated() && |
|
62 | 5 | $this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL && |
|
63 | 5 | !$this->output->getWasWritten(); |
|
64 | |||
65 | 5 | if ($shouldReplaceTaskMark) { |
|
66 | $this->output->writeln("\r\033[K\033[1A\r<info>✔</info>"); |
||
67 | } else { |
||
68 | 5 | if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { |
|
69 | 4 | $this->output->writeln("<info>✔</info> Ok"); |
|
70 | } else { |
||
71 | 1 | $this->output->writeln("<info>✔</info> Ok [$taskTime]"); |
|
72 | } |
||
73 | } |
||
74 | 5 | } |
|
75 | |||
76 | 2 | public function endOnHost(string $hostname) |
|
77 | { |
||
78 | 2 | if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
|
79 | $this->output->writeln("<info>•</info> done on [$hostname]"); |
||
80 | } |
||
81 | 2 | } |
|
82 | |||
83 | /** |
||
84 | * Print error. |
||
85 | * |
||
86 | * @param bool $nonFatal |
||
87 | */ |
||
88 | 2 | public function taskError($nonFatal = true) |
|
96 | |||
97 | /** |
||
98 | * @param \Throwable $exception |
||
99 | * @param Host $host |
||
100 | */ |
||
101 | public function taskException($exception, $host = null) |
||
144 | } |
||
145 |