Simplified DisableKeyCommand using SymfonyStyle

This commit is contained in:
Alejandro Celaya 2017-12-27 17:32:39 +01:00
parent cc3362837b
commit 37fb7e76d9

View file

@ -8,6 +8,7 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Zend\I18n\Translator\TranslatorInterface; use Zend\I18n\Translator\TranslatorInterface;
class DisableKeyCommand extends Command class DisableKeyCommand extends Command
@ -40,18 +41,13 @@ class DisableKeyCommand extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
$apiKey = $input->getArgument('apiKey'); $apiKey = $input->getArgument('apiKey');
$io = new SymfonyStyle($input, $output);
try { try {
$this->apiKeyService->disable($apiKey); $this->apiKeyService->disable($apiKey);
$output->writeln(sprintf( $io->success(sprintf($this->translator->translate('API key "%s" properly disabled'), $apiKey));
$this->translator->translate('API key %s properly disabled'),
'<info>' . $apiKey . '</info>'
));
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
$output->writeln(sprintf( $io->error(sprintf($this->translator->translate('API key "%s" does not exist.'), $apiKey));
'<error>' . $this->translator->translate('API key "%s" does not exist.') . '</error>',
$apiKey
));
} }
} }
} }