|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cushon\HealthBundle\Formatter\Console\StyledOutput\Dependency; |
|
6
|
|
|
|
|
7
|
|
|
use Cushon\HealthBundle\Formatter\Console\StyledOutput\Dependency; |
|
8
|
|
|
use Cushon\HealthBundle\Formatter\Console\StyledOutput\Dependency\DependencyTable\DependencyRowFactory; |
|
9
|
|
|
use Cushon\HealthBundle\Formatter\Console\StyledOutput\Dependency\DependencyTable\TableHeaderFactory; |
|
10
|
|
|
use Cushon\HealthBundle\Message\Result\HealthCheck; |
|
11
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
13
|
|
|
|
|
14
|
|
|
final class DependencyTable implements Dependency |
|
15
|
|
|
{ |
|
16
|
|
|
private DependencyTable\TableHeaderFactory $tableHeaderFactory; |
|
17
|
|
|
private DependencyTable\DependencyRowFactory $dependencyRowFactory; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct( |
|
20
|
|
|
TableHeaderFactory $tableHeaderFactory, |
|
21
|
|
|
DependencyRowFactory $dependencyRowFactory |
|
22
|
|
|
) { |
|
23
|
|
|
$this->tableHeaderFactory = $tableHeaderFactory; |
|
24
|
|
|
$this->dependencyRowFactory = $dependencyRowFactory; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritDoc |
|
29
|
|
|
*/ |
|
30
|
|
|
public function format(HealthCheck $healthCheck, SymfonyStyle $styler): void |
|
31
|
|
|
{ |
|
32
|
|
|
$table = $styler->createTable(); |
|
33
|
|
|
|
|
34
|
|
|
$table->setHeaderTitle('Dependencies'); |
|
35
|
|
|
$this->addDependencyRows($healthCheck, $table); |
|
36
|
|
|
$this->addHeaders($healthCheck, $table); |
|
37
|
|
|
$table->render(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param HealthCheck $healthCheck |
|
42
|
|
|
* @param Table $table |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
private function addHeaders(HealthCheck $healthCheck, Table $table): void |
|
46
|
|
|
{ |
|
47
|
|
|
$table->setHeaders(iterator_to_array($this->tableHeaderFactory->createHeaders($healthCheck))); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param HealthCheck $healthCheck |
|
52
|
|
|
* @param Table $table |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
private function addDependencyRows(HealthCheck $healthCheck, Table $table): void |
|
56
|
|
|
{ |
|
57
|
|
|
foreach ($healthCheck->dependencies() as $dependency) { |
|
58
|
|
|
$table->addRow(iterator_to_array( |
|
59
|
|
|
$this->dependencyRowFactory->createDependencyRow($dependency) |
|
60
|
|
|
)); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|