1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bobbyshaw\WatsonVisualRecognition\Commands; |
4
|
|
|
|
5
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Message\ClassifiersResponse; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Helper\Table; |
11
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Classifier; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Command to get a list of classifiers |
15
|
|
|
* |
16
|
|
|
* @package Bobbyshaw\WatsonVisualRecognition\Commands |
17
|
|
|
* @author Tom Robertshaw <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class GetClassifiersCommand extends BaseCommand |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Configure command |
23
|
|
|
*/ |
24
|
|
|
protected function configure() |
25
|
|
|
{ |
26
|
|
|
$this |
27
|
|
|
->setName('classifiers:get') |
28
|
|
|
->setDescription('Get Classifiers') |
29
|
|
|
->addArgument( |
30
|
|
|
'username', |
31
|
|
|
InputArgument::REQUIRED, |
32
|
|
|
'IBM Watson Service credentials username.' |
33
|
|
|
) |
34
|
|
|
->addArgument( |
35
|
|
|
'password', |
36
|
|
|
InputArgument::REQUIRED, |
37
|
|
|
'IBM Watson Service credentials password.' |
38
|
|
|
) |
39
|
|
|
->addOption( |
40
|
|
|
'version-date', |
41
|
|
|
'-d', |
42
|
|
|
InputOption::VALUE_REQUIRED, |
43
|
|
|
'API version date, defaults to current date i.e. latest release' |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Execute command |
49
|
|
|
* |
50
|
|
|
* @param InputInterface $input |
51
|
|
|
* @param OutputInterface $output |
52
|
|
|
* @return void |
53
|
|
|
* @throws \Exception |
54
|
|
|
*/ |
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
56
|
|
|
{ |
57
|
|
|
$config = [ |
58
|
|
|
'username' => $input->getArgument('username'), |
59
|
|
|
'password' => $input->getArgument('password'), |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
if ($version = $input->getOption('version-date')) { |
63
|
|
|
$config['version'] = $version; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->client->initialize($config); |
67
|
|
|
|
68
|
|
|
$request = $this->client->getClassifiers(); |
69
|
|
|
|
70
|
|
|
/** @var ClassifiersResponse $response */ |
71
|
|
|
$response = $request->send(); |
72
|
|
|
|
73
|
|
|
$classifiers = $response->getClassifiers(); |
74
|
|
|
|
75
|
|
|
$tableRows = []; |
76
|
|
|
/** @var Classifier $classifier */ |
77
|
|
|
foreach ($classifiers as $classifier) { |
78
|
|
|
$tableRows[] = [$classifier->getId(), $classifier->getName()]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$table = new Table($output); |
82
|
|
|
$table->setHeaders(['ID', 'Name'])->setRows($tableRows)->render(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|