shortUrlService = $shortUrlService;
}
public function configure()
{
$this->setName('shortcode:list')
->setDescription('List all short URLs')
->addOption(
'page',
'p',
InputOption::VALUE_OPTIONAL,
sprintf('The first page to list (%s items per page)', PaginableRepositoryAdapter::ITEMS_PER_PAGE),
1
);
}
public function execute(InputInterface $input, OutputInterface $output)
{
$page = intval($input->getOption('page'));
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
do {
$result = $this->shortUrlService->listShortUrls($page);
$page++;
$table = new Table($output);
$table->setHeaders([
'Short code',
'Original URL',
'Date created',
'Visits count',
]);
foreach ($result as $row) {
$table->addRow(array_values($row->jsonSerialize()));
}
$table->render();
if ($this->isLastPage($result)) {
$continue = false;
$output->writeln('You have reached last page');
} else {
$continue = $helper->ask($input, $output, new ConfirmationQuestion(
sprintf('Continue with page %s>? (y/N) ', $page),
false
));
}
} while ($continue);
}
}