1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cushon\HealthBundle\Formatter\Console; |
6
|
|
|
|
7
|
|
|
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus; |
8
|
|
|
use Cushon\HealthBundle\Formatter\Console; |
9
|
|
|
use Cushon\HealthBundle\Formatter\Console\StyledOutput\ApplicationStatus; |
10
|
|
|
use Cushon\HealthBundle\Formatter\Console\StyledOutput\Dependency; |
11
|
|
|
use Cushon\HealthBundle\Message\Result\HealthCheck; |
12
|
|
|
use Symfony\Component\Console\Helper\Table; |
13
|
|
|
use Symfony\Component\Console\Helper\TableCell; |
14
|
|
|
use Symfony\Component\Console\Helper\TableCellStyle; |
15
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
16
|
|
|
|
17
|
|
|
final class StyledOutput implements Console |
18
|
|
|
{ |
19
|
|
|
public const STATUS_HEALTHY = 'Healthy'; |
20
|
|
|
public const STATUS_UNHEALTHY = 'Unhealthy'; |
21
|
|
|
|
22
|
|
|
private SymfonyStyle $styler; |
23
|
|
|
private Dependency $dependencyFormatter; |
24
|
|
|
private ApplicationStatus $applicationStatusFormatter; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param SymfonyStyle $styler |
28
|
|
|
* @param ApplicationStatus $applicationStatusFormatter |
29
|
|
|
* @param Dependency $dependencyFormatter |
30
|
|
|
*/ |
31
|
|
|
public function __construct( |
32
|
|
|
SymfonyStyle $styler, |
33
|
|
|
ApplicationStatus $applicationStatusFormatter, |
34
|
|
|
Dependency $dependencyFormatter |
35
|
|
|
) { |
36
|
|
|
$this->styler = $styler; |
37
|
|
|
$this->dependencyFormatter = $dependencyFormatter; |
38
|
|
|
$this->applicationStatusFormatter = $applicationStatusFormatter; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritDoc |
43
|
|
|
*/ |
44
|
|
|
public function format(HealthCheck $healthCheck): void |
45
|
|
|
{ |
46
|
|
|
$styler = $this->getHealthReportStyler($healthCheck); |
47
|
|
|
|
48
|
|
|
$this->applicationStatusFormatter->format($healthCheck, $styler); |
49
|
|
|
$this->dependencyFormatter->format($healthCheck, $styler); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param HealthCheck $healthCheck |
54
|
|
|
* @return SymfonyStyle |
55
|
|
|
*/ |
56
|
|
|
private function getHealthReportStyler(HealthCheck $healthCheck): SymfonyStyle |
57
|
|
|
{ |
58
|
|
|
return $healthCheck->isHealthy() ? $this->styler : $this->styler->getErrorStyle(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|