1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoctrineORMModule\Diagnostics; |
4
|
|
|
|
5
|
|
|
use DoctrineModule\Component\Console\Output\PropertyOutput; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use ZendDiagnostics\Check\AbstractCheck; |
10
|
|
|
use ZendDiagnostics\Result\Failure; |
11
|
|
|
use ZendDiagnostics\Result\ResultInterface; |
12
|
|
|
use ZendDiagnostics\Result\Success; |
13
|
|
|
|
14
|
|
|
class CheckCommand extends AbstractCheck |
15
|
|
|
{ |
16
|
|
|
/** @var Command */ |
17
|
|
|
private $command; |
18
|
|
|
|
19
|
|
|
/** @var InputInterface */ |
20
|
|
|
private $input; |
21
|
|
|
|
22
|
|
|
/** @var OutputInterface */ |
23
|
|
|
private $output; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* CheckSchema constructor. |
27
|
|
|
* @param Command $command |
28
|
|
|
* @param InputInterface $input |
29
|
|
|
* @param OutputInterface $output |
30
|
|
|
*/ |
31
|
4 |
|
public function __construct(Command $command, InputInterface $input, OutputInterface $output) |
32
|
|
|
{ |
33
|
4 |
|
$this->command = $command; |
34
|
4 |
|
$this->input = $input; |
35
|
4 |
|
$this->output = $output; |
36
|
4 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Perform the actual check and return a ResultInterface |
40
|
|
|
* |
41
|
|
|
* @return ResultInterface |
42
|
|
|
* @throws \Exception |
43
|
|
|
*/ |
44
|
3 |
|
public function check() |
45
|
|
|
{ |
46
|
3 |
|
$exitCode = $this->command->run($this->input, $this->output); |
47
|
|
|
|
48
|
3 |
|
$data = []; |
49
|
3 |
|
if ($this->output instanceof PropertyOutput) { |
50
|
1 |
|
$data = $this->output->getMessage(); |
51
|
1 |
|
if (!is_array($data)) { |
52
|
1 |
|
$data = explode(PHP_EOL, trim($data)); |
53
|
1 |
|
} |
54
|
1 |
|
} |
55
|
|
|
|
56
|
3 |
|
if ($exitCode < 1) { |
57
|
1 |
|
return new Success(get_class($this->command), $data); |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
return new Failure(get_class($this->command), $data); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|