1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bobbyshaw\WatsonVisualRecognition\Commands; |
4
|
|
|
|
5
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Message\DeleteClassifierRequest; |
6
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Message\Response; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Command to delete a classifier |
13
|
|
|
* |
14
|
|
|
* @package Bobbyshaw\WatsonVisualRecognition\Commands |
15
|
|
|
* @author Tom Robertshaw <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class DeleteClassifierCommand extends BaseCommand |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Configure command |
21
|
|
|
*/ |
22
|
2 |
|
protected function configure() |
23
|
|
|
{ |
24
|
2 |
|
parent::configure(); |
25
|
|
|
|
26
|
2 |
|
$this |
27
|
2 |
|
->setName('classifier:delete') |
28
|
2 |
|
->setDescription('Delete Classifier') |
29
|
2 |
|
->addArgument( |
30
|
2 |
|
'classifier_id', |
31
|
2 |
|
InputArgument::REQUIRED, |
32
|
|
|
'Classifier ID' |
33
|
2 |
|
); |
34
|
2 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Execute command |
38
|
|
|
* |
39
|
|
|
* @param InputInterface $input |
40
|
|
|
* @param OutputInterface $output |
41
|
|
|
* @return void |
42
|
|
|
* @throws \Exception |
43
|
|
|
*/ |
44
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
45
|
|
|
{ |
46
|
|
|
$config = [ |
47
|
2 |
|
'username' => $input->getArgument('username'), |
48
|
2 |
|
'password' => $input->getArgument('password'), |
49
|
2 |
|
]; |
50
|
|
|
|
51
|
2 |
|
if ($version = $input->getOption('version-date')) { |
52
|
2 |
|
$config['version'] = $version; |
53
|
2 |
|
} |
54
|
|
|
|
55
|
2 |
|
$this->client->initialize($config); |
56
|
|
|
|
57
|
|
|
/** @var DeleteClassifierRequest $request */ |
58
|
2 |
|
$request = $this->client->deleteClassifier(['classifier_id' => $input->getArgument('classifier_id')]); |
59
|
|
|
|
60
|
|
|
/** @var Response $response */ |
61
|
2 |
|
$response = $request->send(); |
62
|
|
|
|
63
|
2 |
|
if ($response->isSuccessful()) { |
64
|
1 |
|
$output->writeln(sprintf("<info>Classifier %s successfully deleted.</info>", $request->getClassifierId())); |
65
|
2 |
|
} elseif ($error = $response->getErrorMessage()) { |
66
|
1 |
|
$output->writeln(sprintf("<error>%s</error>", $error)); |
67
|
1 |
|
} |
68
|
2 |
|
} |
69
|
|
|
} |
70
|
|
|
|