mirror of
https://github.com/shlinkio/shlink.git
synced 2026-10-12 05:24:49 -05:00
Updated CLI command to create short URLs so that it respects configs for short code length
This commit is contained in:
1 parent
51e130c7a0
commit
33a404f051
5 files changed
+19
-4
No files matched your search
+1
-1
@@ -49,7 +49,7 @@
|
|||||||
"pugx/shortid-php": "^0.5",
|
"pugx/shortid-php": "^0.5",
|
||||||
"shlinkio/shlink-common": "^2.7.0",
|
"shlinkio/shlink-common": "^2.7.0",
|
||||||
"shlinkio/shlink-event-dispatcher": "^1.3",
|
"shlinkio/shlink-event-dispatcher": "^1.3",
|
||||||
"shlinkio/shlink-installer": "^4.1.0",
|
"shlinkio/shlink-installer": "^4.2.0",
|
||||||
"shlinkio/shlink-ip-geolocation": "^1.3.1",
|
"shlinkio/shlink-ip-geolocation": "^1.3.1",
|
||||||
"symfony/console": "^5.0",
|
"symfony/console": "^5.0",
|
||||||
"symfony/filesystem": "^5.0",
|
"symfony/filesystem": "^5.0",
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ return [
|
|||||||
Option\TaskWorkerNumConfigOption::class,
|
Option\TaskWorkerNumConfigOption::class,
|
||||||
Option\WebWorkerNumConfigOption::class,
|
Option\WebWorkerNumConfigOption::class,
|
||||||
Option\RedisServersConfigOption::class,
|
Option\RedisServersConfigOption::class,
|
||||||
|
Option\ShortCodeLengthOption::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'installation_commands' => [
|
'installation_commands' => [
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ return [
|
|||||||
ConfigAbstractFactory::class => [
|
ConfigAbstractFactory::class => [
|
||||||
GeolocationDbUpdater::class => [DbUpdater::class, Reader::class, 'Shlinkio\Shlink\LocalLockFactory'],
|
GeolocationDbUpdater::class => [DbUpdater::class, Reader::class, 'Shlinkio\Shlink\LocalLockFactory'],
|
||||||
|
|
||||||
Command\ShortUrl\GenerateShortUrlCommand::class => [Service\UrlShortener::class, 'config.url_shortener.domain'],
|
Command\ShortUrl\GenerateShortUrlCommand::class => [
|
||||||
|
Service\UrlShortener::class,
|
||||||
|
'config.url_shortener.domain',
|
||||||
|
'config.url_shortener.default_short_codes_length',
|
||||||
|
],
|
||||||
Command\ShortUrl\ResolveUrlCommand::class => [Service\ShortUrl\ShortUrlResolver::class],
|
Command\ShortUrl\ResolveUrlCommand::class => [Service\ShortUrl\ShortUrlResolver::class],
|
||||||
Command\ShortUrl\ListShortUrlsCommand::class => [Service\ShortUrlService::class, 'config.url_shortener.domain'],
|
Command\ShortUrl\ListShortUrlsCommand::class => [Service\ShortUrlService::class, 'config.url_shortener.domain'],
|
||||||
Command\ShortUrl\GetVisitsCommand::class => [Service\VisitsTracker::class],
|
Command\ShortUrl\GetVisitsCommand::class => [Service\VisitsTracker::class],
|
||||||
|
|||||||
@@ -30,12 +30,14 @@ class GenerateShortUrlCommand extends Command
|
|||||||
|
|
||||||
private UrlShortenerInterface $urlShortener;
|
private UrlShortenerInterface $urlShortener;
|
||||||
private array $domainConfig;
|
private array $domainConfig;
|
||||||
|
private int $defaultShortCodeLength;
|
||||||
|
|
||||||
public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig)
|
public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig, int $defaultShortCodeLength)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->urlShortener = $urlShortener;
|
$this->urlShortener = $urlShortener;
|
||||||
$this->domainConfig = $domainConfig;
|
$this->domainConfig = $domainConfig;
|
||||||
|
$this->defaultShortCodeLength = $defaultShortCodeLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
@@ -87,6 +89,12 @@ class GenerateShortUrlCommand extends Command
|
|||||||
'd',
|
'd',
|
||||||
InputOption::VALUE_REQUIRED,
|
InputOption::VALUE_REQUIRED,
|
||||||
'The domain to which this short URL will be attached.',
|
'The domain to which this short URL will be attached.',
|
||||||
|
)
|
||||||
|
->addOption(
|
||||||
|
'shortCodeLength',
|
||||||
|
'l',
|
||||||
|
InputOption::VALUE_REQUIRED,
|
||||||
|
'The length for generated short code (it will be ignored if --customSlug was provided).',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +125,7 @@ class GenerateShortUrlCommand extends Command
|
|||||||
$tags = unique(flatten(array_map($explodeWithComma, $input->getOption('tags'))));
|
$tags = unique(flatten(array_map($explodeWithComma, $input->getOption('tags'))));
|
||||||
$customSlug = $input->getOption('customSlug');
|
$customSlug = $input->getOption('customSlug');
|
||||||
$maxVisits = $input->getOption('maxVisits');
|
$maxVisits = $input->getOption('maxVisits');
|
||||||
|
$shortCodeLength = $input->getOption('shortCodeLength') ?? $this->defaultShortCodeLength;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$shortUrl = $this->urlShortener->urlToShortCode(
|
$shortUrl = $this->urlShortener->urlToShortCode(
|
||||||
@@ -129,6 +138,7 @@ class GenerateShortUrlCommand extends Command
|
|||||||
ShortUrlMetaInputFilter::MAX_VISITS => $maxVisits !== null ? (int) $maxVisits : null,
|
ShortUrlMetaInputFilter::MAX_VISITS => $maxVisits !== null ? (int) $maxVisits : null,
|
||||||
ShortUrlMetaInputFilter::FIND_IF_EXISTS => $input->getOption('findIfExists'),
|
ShortUrlMetaInputFilter::FIND_IF_EXISTS => $input->getOption('findIfExists'),
|
||||||
ShortUrlMetaInputFilter::DOMAIN => $input->getOption('domain'),
|
ShortUrlMetaInputFilter::DOMAIN => $input->getOption('domain'),
|
||||||
|
ShortUrlMetaInputFilter::SHORT_CODE_LENGTH => $shortCodeLength,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class GenerateShortUrlCommandTest extends TestCase
|
|||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->urlShortener = $this->prophesize(UrlShortener::class);
|
$this->urlShortener = $this->prophesize(UrlShortener::class);
|
||||||
$command = new GenerateShortUrlCommand($this->urlShortener->reveal(), self::DOMAIN_CONFIG);
|
$command = new GenerateShortUrlCommand($this->urlShortener->reveal(), self::DOMAIN_CONFIG, 5);
|
||||||
$app = new Application();
|
$app = new Application();
|
||||||
$app->add($command);
|
$app->add($command);
|
||||||
$this->commandTester = new CommandTester($command);
|
$this->commandTester = new CommandTester($command);
|
||||||
|
|||||||
Reference in new issue
Block a user