1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\MonitorBundle\Helper; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
use ZendDiagnostics\Check\CheckInterface; |
8
|
|
|
use ZendDiagnostics\Result\ResultInterface; |
9
|
|
|
use ZendDiagnostics\Result\SkipInterface; |
10
|
|
|
use ZendDiagnostics\Result\SuccessInterface; |
11
|
|
|
use ZendDiagnostics\Result\WarningInterface; |
12
|
|
|
use ZendDiagnostics\Runner\Reporter\ReporterInterface; |
13
|
|
|
use ZendDiagnostics\Result\Collection as ResultsCollection; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Kevin Bond <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class ConsoleReporter implements ReporterInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var OutputInterface |
22
|
|
|
*/ |
23
|
|
|
protected $output; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Should we hide the output when it is OK? |
27
|
|
|
* |
28
|
|
|
* @var bool |
29
|
|
|
*/ |
30
|
|
|
protected $suppressOKs = false; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param OutputInterface $output |
34
|
|
|
*/ |
35
|
|
|
public function __construct(OutputInterface $output = null) |
36
|
|
|
{ |
37
|
|
|
if (null === $output) { |
38
|
|
|
$output = new ConsoleOutput(); |
39
|
|
|
} |
40
|
|
|
$this->output = $output; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function suppressOKs($suppressOKs) |
44
|
|
|
{ |
45
|
|
|
$this->suppressOKs = $suppressOKs; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null) |
52
|
|
|
{ |
53
|
|
|
switch (true) { |
54
|
|
|
case $result instanceof SuccessInterface: |
55
|
|
|
if ($this->suppressOKs) { |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->output->write('<info>OK</info>'); |
60
|
|
|
break; |
61
|
|
|
|
62
|
|
|
case $result instanceof WarningInterface: |
63
|
|
|
$this->output->write('<comment>WARNING</comment>'); |
64
|
|
|
break; |
65
|
|
|
|
66
|
|
|
case $result instanceof SkipInterface: |
67
|
|
|
$this->output->write('<question>SKIP</question>'); |
68
|
|
|
break; |
69
|
|
|
|
70
|
|
|
default: |
71
|
|
|
$this->output->write('<error>FAIL</error>'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->output->write(sprintf(' %s', $check->getLabel())); |
75
|
|
|
|
76
|
|
|
if ($message = $result->getMessage()) { |
77
|
|
|
$this->output->write(sprintf(': %s', $message)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->output->writeln(''); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function onStart(\ArrayObject $checks, $runnerConfig) |
87
|
|
|
{ |
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function onBeforeRun(CheckInterface $check, $checkAlias = null) |
95
|
|
|
{ |
96
|
|
|
return; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function onStop(ResultsCollection $results) |
103
|
|
|
{ |
104
|
|
|
return; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
|
|
public function onFinish(ResultsCollection $results) |
111
|
|
|
{ |
112
|
|
|
return; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|