1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bobbyshaw\WatsonVisualRecognition\Commands; |
4
|
|
|
|
5
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Message\ClassifierResponse; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Helper\Table; |
10
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Classifier; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Command to get a classifier detail |
14
|
|
|
* |
15
|
|
|
* @package Bobbyshaw\WatsonVisualRecognition\Commands |
16
|
|
|
* @author Tom Robertshaw <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class GetClassifierCommand extends BaseCommand |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Configure command |
22
|
|
|
*/ |
23
|
1 |
|
protected function configure() |
24
|
|
|
{ |
25
|
1 |
|
parent::configure(); |
26
|
|
|
|
27
|
1 |
|
$this |
28
|
1 |
|
->setName('classifier:get') |
29
|
1 |
|
->setDescription('Get Classifier') |
30
|
1 |
|
->addArgument( |
31
|
1 |
|
'classifier_id', |
32
|
1 |
|
InputArgument::REQUIRED, |
33
|
|
|
'Classifier ID' |
34
|
1 |
|
); |
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Execute command |
39
|
|
|
* |
40
|
|
|
* @param InputInterface $input |
41
|
|
|
* @param OutputInterface $output |
42
|
|
|
* @return void |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
46
|
|
|
{ |
47
|
|
|
$config = [ |
48
|
1 |
|
'username' => $input->getArgument('username'), |
49
|
1 |
|
'password' => $input->getArgument('password'), |
50
|
1 |
|
]; |
51
|
|
|
|
52
|
1 |
|
if ($version = $input->getOption('version-date')) { |
53
|
1 |
|
$config['version'] = $version; |
54
|
1 |
|
} |
55
|
|
|
|
56
|
1 |
|
$this->client->initialize($config); |
57
|
|
|
|
58
|
1 |
|
$request = $this->client->getClassifier(['classifier_id' => $input->getArgument('classifier_id')]); |
59
|
|
|
|
60
|
|
|
/** @var ClassifierResponse $response */ |
61
|
1 |
|
$response = $request->send(); |
62
|
|
|
|
63
|
|
|
/** @var Classifier $classifier */ |
64
|
1 |
|
$classifier = $response->getClassifier(); |
65
|
|
|
|
66
|
1 |
|
$headers = ['ID', 'Name', 'Owner', 'Created At']; |
67
|
|
|
$tableRows = [ |
68
|
|
|
[ |
69
|
1 |
|
$classifier->getId(), |
70
|
1 |
|
$classifier->getName(), |
71
|
1 |
|
$classifier->getOwner(), |
72
|
1 |
|
$classifier->getCreated()->format('Y-m-d H:i:s') |
73
|
1 |
|
] |
74
|
1 |
|
]; |
75
|
|
|
|
76
|
1 |
|
$table = new Table($output); |
77
|
1 |
|
$table->setHeaders($headers)->setRows($tableRows)->render(); |
78
|
1 |
|
} |
79
|
|
|
} |
80
|
|
|
|