1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package: chapi |
4
|
|
|
* |
5
|
|
|
* @author: msiebeneicher |
6
|
|
|
* @since: 2015-07-30 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Chapi\Commands; |
11
|
|
|
|
12
|
|
|
use Chapi\Service\JobRepository\JobRepositoryInterface; |
13
|
|
|
use Symfony\Component\Console\Helper\Table; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
|
16
|
|
|
class InfoCommand extends AbstractCommand |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Configures the current command. |
20
|
|
|
*/ |
21
|
1 |
|
protected function configure() |
22
|
|
|
{ |
23
|
1 |
|
$this->setName('info') |
24
|
1 |
|
->setDescription('Display your job information from chronos') |
25
|
1 |
|
->addArgument('jobName', InputArgument::REQUIRED, 'selected job') |
26
|
|
|
; |
27
|
1 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return int |
31
|
|
|
*/ |
32
|
1 |
|
protected function process() |
33
|
|
|
{ |
34
|
1 |
|
$_sJobName = $this->oInput->getArgument('jobName'); |
35
|
|
|
|
36
|
1 |
|
$_oChronosJobEntity = $this->checkInChronos($_sJobName); |
37
|
1 |
|
$_oJobEntity = $_oChronosJobEntity == null ? $this->checkInMarathon($_sJobName) : $_oChronosJobEntity; |
38
|
|
|
|
39
|
1 |
|
if (!$_oJobEntity) |
40
|
1 |
|
{ |
41
|
|
|
$this->oOutput->writeln(sprintf('<fg=red>%s</>', 'Could not find the job.')); |
42
|
|
|
return 1; |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
$this->oOutput->writeln(sprintf("\n<comment>info '%s'</comment>\n", $_oJobEntity->getKey())); |
46
|
|
|
|
47
|
1 |
|
$_oTable = new Table($this->oOutput); |
48
|
1 |
|
$_oTable->setHeaders(array('Property', 'Value')); |
49
|
|
|
|
50
|
1 |
|
foreach ($_oJobEntity as $_sKey => $_mValue) |
51
|
|
|
{ |
52
|
1 |
|
if (is_array($_mValue) || is_object($_mValue)) |
53
|
1 |
|
{ |
54
|
1 |
|
$_sEmptyString = (is_object($_mValue)) ? '{ }' : '[ ]'; |
55
|
|
|
|
56
|
1 |
|
$_mValue = (!empty($_mValue)) |
57
|
1 |
|
? json_encode($_mValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) |
58
|
1 |
|
: $_sEmptyString; |
59
|
1 |
|
} |
60
|
1 |
|
elseif (is_bool($_mValue)) |
61
|
|
|
{ |
62
|
1 |
|
$_mValue = (true === $_mValue) |
63
|
1 |
|
? 'true' |
64
|
1 |
|
: 'false'; |
65
|
1 |
|
} |
66
|
|
|
|
67
|
1 |
|
$_oTable->addRow(array($_sKey, $_mValue)); |
68
|
1 |
|
} |
69
|
|
|
|
70
|
1 |
|
$_oTable->render(); |
71
|
|
|
|
72
|
1 |
|
return 0; |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
private function checkInChronos($sJobName) |
76
|
|
|
{ |
77
|
|
|
/** @var JobRepositoryInterface $_oJobRepositoryChronos */ |
78
|
1 |
|
$_oJobRepositoryChronos = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_CHRONOS); |
79
|
1 |
|
return $_oJobRepositoryChronos->getJob($sJobName); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function checkInMarathon($sJobName) |
83
|
|
|
{ |
84
|
|
|
/** @var JobRepositoryInterface $_oJobRepositoryMarathon */ |
85
|
|
|
$_oJobRepositoryMarathon = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_MARATHON); |
86
|
|
|
return $_oJobRepositoryMarathon->getJob($sJobName); |
87
|
|
|
} |
88
|
|
|
} |