urlShortener = $urlShortener; $this->translator = $translator; parent::__construct(null); } public function configure() { $this->setName(self::NAME) ->setDescription($this->translator->translate('Returns the long URL behind a short code')) ->addArgument( 'shortCode', InputArgument::REQUIRED, $this->translator->translate('The short code to parse') ); } public function interact(InputInterface $input, OutputInterface $output) { $shortCode = $input->getArgument('shortCode'); if (! empty($shortCode)) { return; } $io = new SymfonyStyle($input, $output); $shortCode = $io->ask( $this->translator->translate('A short code was not provided. Which short code do you want to parse?') ); if (! empty($shortCode)) { $input->setArgument('shortCode', $shortCode); } } public function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $shortCode = $input->getArgument('shortCode'); try { $longUrl = $this->urlShortener->shortCodeToUrl($shortCode); $output->writeln(\sprintf('%s %s', $this->translator->translate('Long URL:'), $longUrl)); } catch (InvalidShortCodeException $e) { $io->error( \sprintf($this->translator->translate('Provided short code "%s" has an invalid format.'), $shortCode) ); } catch (EntityDoesNotExistException $e) { $io->error( \sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode) ); } } }