mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-23 21:27:44 +03:00
Replaced commands namespace shortcode by short-code, using the old one as an alias
This commit is contained in:
parent
5b9784cd9e
commit
4f2146dd9c
5 changed files with 114 additions and 99 deletions
|
@ -14,7 +14,8 @@ use Zend\I18n\Translator\TranslatorInterface;
|
||||||
|
|
||||||
class GeneratePreviewCommand extends Command
|
class GeneratePreviewCommand extends Command
|
||||||
{
|
{
|
||||||
const NAME = 'shortcode:process-previews';
|
public const NAME = 'short-code:process-previews';
|
||||||
|
private const ALIASES = ['shortcode:process-previews'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PreviewGeneratorInterface
|
* @var PreviewGeneratorInterface
|
||||||
|
@ -40,17 +41,19 @@ class GeneratePreviewCommand extends Command
|
||||||
parent::__construct(null);
|
parent::__construct(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->setName(self::NAME)
|
$this
|
||||||
->setDescription(
|
->setName(self::NAME)
|
||||||
$this->translator->translate(
|
->setAliases(self::ALIASES)
|
||||||
'Processes and generates the previews for every URL, improving performance for later web requests.'
|
->setDescription(
|
||||||
)
|
$this->translator->translate(
|
||||||
);
|
'Processes and generates the previews for every URL, improving performance for later web requests.'
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$page = 1;
|
$page = 1;
|
||||||
do {
|
do {
|
||||||
|
@ -65,7 +68,7 @@ class GeneratePreviewCommand extends Command
|
||||||
(new SymfonyStyle($input, $output))->success($this->translator->translate('Finished processing all URLs'));
|
(new SymfonyStyle($input, $output))->success($this->translator->translate('Finished processing all URLs'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processUrl($url, OutputInterface $output)
|
private function processUrl($url, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$output->write(\sprintf($this->translator->translate('Processing URL %s...'), $url));
|
$output->write(\sprintf($this->translator->translate('Processing URL %s...'), $url));
|
||||||
|
|
|
@ -20,7 +20,8 @@ class GenerateShortcodeCommand extends Command
|
||||||
{
|
{
|
||||||
use ShortUrlBuilderTrait;
|
use ShortUrlBuilderTrait;
|
||||||
|
|
||||||
public const NAME = 'shortcode:generate';
|
public const NAME = 'short-code:generate';
|
||||||
|
private const ALIASES = ['shortcode:generate'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var UrlShortenerInterface
|
* @var UrlShortenerInterface
|
||||||
|
@ -46,36 +47,38 @@ class GenerateShortcodeCommand extends Command
|
||||||
parent::__construct(null);
|
parent::__construct(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->setName(self::NAME)
|
$this
|
||||||
->setDescription(
|
->setName(self::NAME)
|
||||||
$this->translator->translate('Generates a short code for provided URL and returns the short URL')
|
->setAliases(self::ALIASES)
|
||||||
)
|
->setDescription(
|
||||||
->addArgument('longUrl', InputArgument::REQUIRED, $this->translator->translate('The long URL to parse'))
|
$this->translator->translate('Generates a short code for provided URL and returns the short URL')
|
||||||
->addOption(
|
)
|
||||||
'tags',
|
->addArgument('longUrl', InputArgument::REQUIRED, $this->translator->translate('The long URL to parse'))
|
||||||
't',
|
->addOption(
|
||||||
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
|
'tags',
|
||||||
$this->translator->translate('Tags to apply to the new short URL')
|
't',
|
||||||
)
|
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
|
||||||
->addOption('validSince', 's', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
$this->translator->translate('Tags to apply to the new short URL')
|
||||||
'The date from which this short URL will be valid. '
|
)
|
||||||
. 'If someone tries to access it before this date, it will not be found.'
|
->addOption('validSince', 's', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
||||||
))
|
'The date from which this short URL will be valid. '
|
||||||
->addOption('validUntil', 'u', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
. 'If someone tries to access it before this date, it will not be found.'
|
||||||
'The date until which this short URL will be valid. '
|
))
|
||||||
. 'If someone tries to access it after this date, it will not be found.'
|
->addOption('validUntil', 'u', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
||||||
))
|
'The date until which this short URL will be valid. '
|
||||||
->addOption('customSlug', 'c', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
. 'If someone tries to access it after this date, it will not be found.'
|
||||||
'If provided, this slug will be used instead of generating a short code'
|
))
|
||||||
))
|
->addOption('customSlug', 'c', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
||||||
->addOption('maxVisits', 'm', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
'If provided, this slug will be used instead of generating a short code'
|
||||||
'This will limit the number of visits for this short URL.'
|
))
|
||||||
));
|
->addOption('maxVisits', 'm', InputOption::VALUE_REQUIRED, $this->translator->translate(
|
||||||
|
'This will limit the number of visits for this short URL.'
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function interact(InputInterface $input, OutputInterface $output)
|
protected function interact(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$longUrl = $input->getArgument('longUrl');
|
$longUrl = $input->getArgument('longUrl');
|
||||||
|
@ -91,7 +94,7 @@ class GenerateShortcodeCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$longUrl = $input->getArgument('longUrl');
|
$longUrl = $input->getArgument('longUrl');
|
||||||
|
@ -140,7 +143,7 @@ class GenerateShortcodeCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getOptionalDate(InputInterface $input, string $fieldName)
|
private function getOptionalDate(InputInterface $input, string $fieldName): ?\DateTime
|
||||||
{
|
{
|
||||||
$since = $input->getOption($fieldName);
|
$since = $input->getOption($fieldName);
|
||||||
return $since !== null ? new \DateTime($since) : null;
|
return $since !== null ? new \DateTime($since) : null;
|
||||||
|
|
|
@ -15,7 +15,8 @@ use Zend\I18n\Translator\TranslatorInterface;
|
||||||
|
|
||||||
class GetVisitsCommand extends Command
|
class GetVisitsCommand extends Command
|
||||||
{
|
{
|
||||||
const NAME = 'shortcode:visits';
|
public const NAME = 'short-code:visits';
|
||||||
|
private const ALIASES = ['shortcode:visits'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var VisitsTrackerInterface
|
* @var VisitsTrackerInterface
|
||||||
|
@ -33,9 +34,11 @@ class GetVisitsCommand extends Command
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->setName(self::NAME)
|
$this
|
||||||
|
->setName(self::NAME)
|
||||||
|
->setAliases(self::ALIASES)
|
||||||
->setDescription(
|
->setDescription(
|
||||||
$this->translator->translate('Returns the detailed visits information for provided short code')
|
$this->translator->translate('Returns the detailed visits information for provided short code')
|
||||||
)
|
)
|
||||||
|
@ -58,7 +61,7 @@ class GetVisitsCommand extends Command
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function interact(InputInterface $input, OutputInterface $output)
|
protected function interact(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$shortCode = $input->getArgument('shortCode');
|
$shortCode = $input->getArgument('shortCode');
|
||||||
if (! empty($shortCode)) {
|
if (! empty($shortCode)) {
|
||||||
|
@ -74,7 +77,7 @@ class GetVisitsCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$shortCode = $input->getArgument('shortCode');
|
$shortCode = $input->getArgument('shortCode');
|
||||||
|
@ -101,7 +104,7 @@ class GetVisitsCommand extends Command
|
||||||
], $rows);
|
], $rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDateOption(InputInterface $input, $key)
|
private function getDateOption(InputInterface $input, $key)
|
||||||
{
|
{
|
||||||
$value = $input->getOption($key);
|
$value = $input->getOption($key);
|
||||||
if (! empty($value)) {
|
if (! empty($value)) {
|
||||||
|
|
|
@ -18,7 +18,8 @@ class ListShortcodesCommand extends Command
|
||||||
{
|
{
|
||||||
use PaginatorUtilsTrait;
|
use PaginatorUtilsTrait;
|
||||||
|
|
||||||
const NAME = 'shortcode:list';
|
public const NAME = 'short-code:list';
|
||||||
|
private const ALIASES = ['shortcode:list'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ShortUrlServiceInterface
|
* @var ShortUrlServiceInterface
|
||||||
|
@ -46,49 +47,51 @@ class ListShortcodesCommand extends Command
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->setName(self::NAME)
|
$this
|
||||||
->setDescription($this->translator->translate('List all short URLs'))
|
->setName(self::NAME)
|
||||||
->addOption(
|
->setAliases(self::ALIASES)
|
||||||
'page',
|
->setDescription($this->translator->translate('List all short URLs'))
|
||||||
'p',
|
->addOption(
|
||||||
InputOption::VALUE_OPTIONAL,
|
'page',
|
||||||
sprintf(
|
'p',
|
||||||
$this->translator->translate('The first page to list (%s items per page)'),
|
InputOption::VALUE_OPTIONAL,
|
||||||
PaginableRepositoryAdapter::ITEMS_PER_PAGE
|
sprintf(
|
||||||
),
|
$this->translator->translate('The first page to list (%s items per page)'),
|
||||||
1
|
PaginableRepositoryAdapter::ITEMS_PER_PAGE
|
||||||
)
|
),
|
||||||
->addOption(
|
1
|
||||||
'searchTerm',
|
)
|
||||||
's',
|
->addOption(
|
||||||
InputOption::VALUE_OPTIONAL,
|
'searchTerm',
|
||||||
$this->translator->translate(
|
's',
|
||||||
'A query used to filter results by searching for it on the longUrl and shortCode fields'
|
InputOption::VALUE_OPTIONAL,
|
||||||
)
|
$this->translator->translate(
|
||||||
)
|
'A query used to filter results by searching for it on the longUrl and shortCode fields'
|
||||||
->addOption(
|
)
|
||||||
'tags',
|
)
|
||||||
't',
|
->addOption(
|
||||||
InputOption::VALUE_OPTIONAL,
|
'tags',
|
||||||
$this->translator->translate('A comma-separated list of tags to filter results')
|
't',
|
||||||
)
|
InputOption::VALUE_OPTIONAL,
|
||||||
->addOption(
|
$this->translator->translate('A comma-separated list of tags to filter results')
|
||||||
'orderBy',
|
)
|
||||||
'o',
|
->addOption(
|
||||||
InputOption::VALUE_OPTIONAL,
|
'orderBy',
|
||||||
$this->translator->translate(
|
'o',
|
||||||
'The field from which we want to order by. Pass ASC or DESC separated by a comma'
|
InputOption::VALUE_OPTIONAL,
|
||||||
)
|
$this->translator->translate(
|
||||||
)
|
'The field from which we want to order by. Pass ASC or DESC separated by a comma'
|
||||||
->addOption(
|
)
|
||||||
'showTags',
|
)
|
||||||
null,
|
->addOption(
|
||||||
InputOption::VALUE_NONE,
|
'showTags',
|
||||||
$this->translator->translate('Whether to display the tags or not')
|
null,
|
||||||
);
|
InputOption::VALUE_NONE,
|
||||||
|
$this->translator->translate('Whether to display the tags or not')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$page = (int) $input->getOption('page');
|
$page = (int) $input->getOption('page');
|
||||||
|
|
|
@ -15,7 +15,8 @@ use Zend\I18n\Translator\TranslatorInterface;
|
||||||
|
|
||||||
class ResolveUrlCommand extends Command
|
class ResolveUrlCommand extends Command
|
||||||
{
|
{
|
||||||
const NAME = 'shortcode:parse';
|
public const NAME = 'short-code:parse';
|
||||||
|
private const ALIASES = ['shortcode:parse'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var UrlShortenerInterface
|
* @var UrlShortenerInterface
|
||||||
|
@ -33,18 +34,20 @@ class ResolveUrlCommand extends Command
|
||||||
parent::__construct(null);
|
parent::__construct(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configure()
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->setName(self::NAME)
|
$this
|
||||||
->setDescription($this->translator->translate('Returns the long URL behind a short code'))
|
->setName(self::NAME)
|
||||||
->addArgument(
|
->setAliases(self::ALIASES)
|
||||||
'shortCode',
|
->setDescription($this->translator->translate('Returns the long URL behind a short code'))
|
||||||
InputArgument::REQUIRED,
|
->addArgument(
|
||||||
$this->translator->translate('The short code to parse')
|
'shortCode',
|
||||||
);
|
InputArgument::REQUIRED,
|
||||||
|
$this->translator->translate('The short code to parse')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function interact(InputInterface $input, OutputInterface $output)
|
protected function interact(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$shortCode = $input->getArgument('shortCode');
|
$shortCode = $input->getArgument('shortCode');
|
||||||
if (! empty($shortCode)) {
|
if (! empty($shortCode)) {
|
||||||
|
@ -60,7 +63,7 @@ class ResolveUrlCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$shortCode = $input->getArgument('shortCode');
|
$shortCode = $input->getArgument('shortCode');
|
||||||
|
|
Loading…
Reference in a new issue