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
|
|
|
* @param OutputInterface $output |
27
|
|
|
*/ |
28
|
|
|
public function __construct(OutputInterface $output = null) |
29
|
|
|
{ |
30
|
|
|
if (null === $output) { |
31
|
|
|
$output = new ConsoleOutput(); |
32
|
|
|
} |
33
|
|
|
$this->output = $output; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null) |
40
|
|
|
{ |
41
|
|
|
switch (true) { |
42
|
|
|
case $result instanceof SuccessInterface: |
43
|
|
|
$this->output->write('<info>OK</info>'); |
44
|
|
|
break; |
45
|
|
|
|
46
|
|
|
case $result instanceof WarningInterface: |
47
|
|
|
$this->output->write('<comment>WARNING</comment>'); |
48
|
|
|
break; |
49
|
|
|
|
50
|
|
|
case $result instanceof SkipInterface: |
51
|
|
|
$this->output->write('<question>SKIP</question>'); |
52
|
|
|
break; |
53
|
|
|
|
54
|
|
|
default: |
55
|
|
|
$this->output->write('<error>FAIL</error>'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->output->write(sprintf(' %s', $check->getLabel())); |
59
|
|
|
|
60
|
|
|
if ($message = $result->getMessage()) { |
61
|
|
|
$this->output->write(sprintf(': %s', $message)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->output->writeln(''); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function onStart(\ArrayObject $checks, $runnerConfig) |
71
|
|
|
{ |
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function onBeforeRun(CheckInterface $check, $checkAlias = null) |
79
|
|
|
{ |
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function onStop(ResultsCollection $results) |
87
|
|
|
{ |
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function onFinish(ResultsCollection $results) |
95
|
|
|
{ |
96
|
|
|
return; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|