mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 07:49:54 +03:00
Added new not found short url config to installer
This commit is contained in:
parent
32fcdd9d94
commit
057f88a36a
2 changed files with 36 additions and 0 deletions
|
@ -19,11 +19,15 @@ class UrlShortenerConfigCustomizer implements ConfigCustomizerInterface
|
|||
public const HOSTNAME = 'HOSTNAME';
|
||||
public const CHARS = 'CHARS';
|
||||
public const VALIDATE_URL = 'VALIDATE_URL';
|
||||
public const ENABLE_NOT_FOUND_REDIRECTION = 'ENABLE_NOT_FOUND_REDIRECTION';
|
||||
public const NOT_FOUND_REDIRECT_TO = 'NOT_FOUND_REDIRECT_TO';
|
||||
private const EXPECTED_KEYS = [
|
||||
self::SCHEMA,
|
||||
self::HOSTNAME,
|
||||
self::CHARS,
|
||||
self::VALIDATE_URL,
|
||||
self::ENABLE_NOT_FOUND_REDIRECTION,
|
||||
self::NOT_FOUND_REDIRECT_TO,
|
||||
];
|
||||
|
||||
public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig): void
|
||||
|
@ -38,6 +42,11 @@ class UrlShortenerConfigCustomizer implements ConfigCustomizerInterface
|
|||
|
||||
$io->title('URL SHORTENER');
|
||||
foreach ($keysToAskFor as $key) {
|
||||
// Skip not found redirect URL when the user decided not to redirect
|
||||
if ($key === self::NOT_FOUND_REDIRECT_TO && ! $urlShortener[self::ENABLE_NOT_FOUND_REDIRECTION]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$urlShortener[$key] = $this->ask($io, $key);
|
||||
}
|
||||
$appConfig->setUrlShortener($urlShortener);
|
||||
|
@ -60,6 +69,18 @@ class UrlShortenerConfigCustomizer implements ConfigCustomizerInterface
|
|||
) ?: str_shuffle(UrlShortener::DEFAULT_CHARS);
|
||||
case self::VALIDATE_URL:
|
||||
return $io->confirm('Do you want to validate long urls by 200 HTTP status code on response');
|
||||
case self::ENABLE_NOT_FOUND_REDIRECTION:
|
||||
return $io->confirm(
|
||||
'Do you want to enable a redirection to a custom URL when a user hits an invalid short URL? ' .
|
||||
'(If not enabled, the user will see a default "404 not found" page)',
|
||||
false
|
||||
);
|
||||
case self::NOT_FOUND_REDIRECT_TO:
|
||||
return $this->askRequired(
|
||||
$io,
|
||||
'redirect URL',
|
||||
'Custom URL to redirect to when a user hits an invalid short URL'
|
||||
);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
|
|
@ -146,6 +146,16 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
|||
UrlShortenerConfigCustomizer::HOSTNAME => ['url_shortener', 'domain', 'hostname'],
|
||||
UrlShortenerConfigCustomizer::CHARS => ['url_shortener', 'shortcode_chars'],
|
||||
UrlShortenerConfigCustomizer::VALIDATE_URL => ['url_shortener', 'validate_url'],
|
||||
UrlShortenerConfigCustomizer::ENABLE_NOT_FOUND_REDIRECTION => [
|
||||
'url_shortener',
|
||||
'not_found_short_url',
|
||||
'enable_redirection',
|
||||
],
|
||||
UrlShortenerConfigCustomizer::NOT_FOUND_REDIRECT_TO => [
|
||||
'url_shortener',
|
||||
'not_found_short_url',
|
||||
'redirect_to',
|
||||
],
|
||||
], $pathCollection));
|
||||
}
|
||||
|
||||
|
@ -191,6 +201,11 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
|||
],
|
||||
'shortcode_chars' => $this->urlShortener[UrlShortenerConfigCustomizer::CHARS] ?? '',
|
||||
'validate_url' => $this->urlShortener[UrlShortenerConfigCustomizer::VALIDATE_URL] ?? true,
|
||||
'not_found_short_url' => [
|
||||
'enable_redirection' =>
|
||||
$this->urlShortener[UrlShortenerConfigCustomizer::ENABLE_NOT_FOUND_REDIRECTION] ?? false,
|
||||
'redirect_to' => $this->urlShortener[UrlShortenerConfigCustomizer::NOT_FOUND_REDIRECT_TO] ?? null,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue