1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Incapsula\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Helper\Table; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class SitesListAttributeCommand extends AbstractCommand |
11
|
|
|
{ |
12
|
|
|
protected function configure() |
13
|
|
|
{ |
14
|
|
|
parent::configure(); |
15
|
|
|
|
16
|
|
|
$this |
17
|
|
|
->setName('sites:listattribute') |
18
|
|
|
->addOption('attribute',null,InputOption::VALUE_REQUIRED, 'json key to inspect') |
19
|
|
|
->setDescription('List a config value from all sites') |
20
|
|
|
; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param InputInterface $input |
25
|
|
|
* @param OutputInterface $output |
26
|
|
|
* |
27
|
|
|
* @return int |
28
|
|
|
*/ |
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
30
|
|
|
{ |
31
|
|
|
$attribute = $input->getOption('attribute'); |
32
|
|
|
|
33
|
|
|
$sites = $this->getSites(); |
34
|
|
|
|
35
|
|
|
$table = new Table($output); |
36
|
|
|
$table->setHeaders(['Site ID', 'Domain', 'Attribute']); |
37
|
|
|
foreach ($sites as $site) { |
38
|
|
|
$table->addRow([$site['site_id'], $site['domain'], $site[$attribute]]); |
39
|
|
|
} |
40
|
|
|
$table->render(); |
41
|
|
|
|
42
|
|
|
return 0; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getSites() |
46
|
|
|
{ |
47
|
|
|
$api = $this->client->sites(); |
48
|
|
|
$sites = []; |
49
|
|
|
$page = 0; |
50
|
|
|
|
51
|
|
|
while (true) { |
52
|
|
|
$resp = $api->list(50, $page); |
53
|
|
|
if (empty($resp['sites'])) { |
54
|
|
|
break; |
55
|
|
|
} |
56
|
|
|
$sites = array_merge($sites, $resp['sites']); |
57
|
|
|
++$page; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $sites; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|