mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-05 23:03:11 +08:00
60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\CLI\Command\ShortUrl;
|
|
|
|
use Shlinkio\Shlink\CLI\Command\Visit\AbstractVisitsListCommand;
|
|
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
|
use Shlinkio\Shlink\Common\Util\DateRange;
|
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
|
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
|
|
use Shlinkio\Shlink\Core\Model\VisitsParams;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
class GetShortUrlVisitsCommand extends AbstractVisitsListCommand
|
|
{
|
|
public const NAME = 'short-url:visits';
|
|
|
|
protected function doConfigure(): void
|
|
{
|
|
$this
|
|
->setName(self::NAME)
|
|
->setDescription('Returns the detailed visits information for provided short code')
|
|
->addArgument('shortCode', InputArgument::REQUIRED, 'The short code which visits we want to get.')
|
|
->addOption('domain', 'd', InputOption::VALUE_REQUIRED, 'The domain for the short code.');
|
|
}
|
|
|
|
protected function interact(InputInterface $input, OutputInterface $output): void
|
|
{
|
|
$shortCode = $input->getArgument('shortCode');
|
|
if (! empty($shortCode)) {
|
|
return;
|
|
}
|
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
$shortCode = $io->ask('A short code was not provided. Which short code do you want to use?');
|
|
if (! empty($shortCode)) {
|
|
$input->setArgument('shortCode', $shortCode);
|
|
}
|
|
}
|
|
|
|
protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator
|
|
{
|
|
$identifier = ShortUrlIdentifier::fromCli($input);
|
|
return $this->visitsHelper->visitsForShortUrl($identifier, new VisitsParams($dateRange));
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function mapExtraFields(Visit $visit): array
|
|
{
|
|
return [];
|
|
}
|
|
}
|