Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new QR code config options #214

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this

## [Unreleased]
### Added
* *Nothing*
* Add QR code options for foreground color, background color and logo URL.

### Changed
* Update dependencies
Expand Down
6 changes: 6 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
'QR codes > Default format' => Config\Option\QrCode\DefaultFormatConfigOption::class,
'QR codes > Default error correction' => Config\Option\QrCode\DefaultErrorCorrectionConfigOption::class,
'QR codes > Default round block size' => Config\Option\QrCode\DefaultRoundBlockSizeConfigOption::class,
'QR codes > Default color' => Config\Option\QrCode\DefaultColorConfigOption::class,
'QR codes > Default background color' => Config\Option\QrCode\DefaultBgColorConfigOption::class,
'QR codes > Default logo URL' => Config\Option\QrCode\DefaultLogoUrlConfigOption::class,
'QR codes > Enabled for disabled short URLs'
=> Config\Option\QrCode\EnabledForDisabledShortUrlsConfigOption::class,
],
Expand Down Expand Up @@ -182,6 +185,9 @@
Config\Option\QrCode\DefaultFormatConfigOption::class => InvokableFactory::class,
Config\Option\QrCode\DefaultErrorCorrectionConfigOption::class => InvokableFactory::class,
Config\Option\QrCode\DefaultRoundBlockSizeConfigOption::class => InvokableFactory::class,
Config\Option\QrCode\DefaultColorConfigOption::class => InvokableFactory::class,
Config\Option\QrCode\DefaultBgColorConfigOption::class => InvokableFactory::class,
Config\Option\QrCode\DefaultLogoUrlConfigOption::class => InvokableFactory::class,
Config\Option\QrCode\EnabledForDisabledShortUrlsConfigOption::class => InvokableFactory::class,
],
],
Expand Down
26 changes: 26 additions & 0 deletions src/Config/Option/QrCode/DefaultBgColorConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\QrCode;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class DefaultBgColorConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
{
return 'DEFAULT_QR_CODE_BG_COLOR';
}

public function ask(StyleInterface $io, array $currentOptions): ?string
{
return $io->ask(
'What\'s the default background color for generated QR codes',
'#FFFFFF',
ConfigOptionsValidator::validateHexColor(...),
);
}
}
26 changes: 26 additions & 0 deletions src/Config/Option/QrCode/DefaultColorConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\QrCode;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class DefaultColorConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
{
return 'DEFAULT_QR_CODE_COLOR';
}

public function ask(StyleInterface $io, array $currentOptions): ?string
{
return $io->ask(
'What\'s the default foreground color for generated QR codes',
'#000000',
ConfigOptionsValidator::validateHexColor(...),
);
}
}
25 changes: 25 additions & 0 deletions src/Config/Option/QrCode/DefaultLogoUrlConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\QrCode;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class DefaultLogoUrlConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
{
return 'DEFAULT_QR_CODE_LOGO_URL';
}

public function ask(StyleInterface $io, array $currentOptions): ?string
{
return $io->ask(
'Provide a URL for a logo to be placed inside the QR code (leave empty to use no logo)',
validator: ConfigOptionsValidator::validateUrl(...),
);
}
}
6 changes: 2 additions & 4 deletions src/Config/Option/QrCode/DefaultMarginConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
namespace Shlinkio\Shlink\Installer\Config\Option\QrCode;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class DefaultMarginConfigOption extends BaseConfigOption
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'DEFAULT_QR_CODE_MARGIN';
Expand All @@ -22,7 +20,7 @@ public function ask(StyleInterface $io, array $currentOptions): int
return $io->ask(
'What\'s the default margin, in pixels, you want generated QR codes to have',
'0',
fn (mixed $value) => $this->validateNumberGreaterThan($value, 0),
fn (mixed $value) => ConfigOptionsValidator::validateNumberGreaterThan($value, 0),
);
}
}
6 changes: 2 additions & 4 deletions src/Config/Option/QrCode/DefaultSizeConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
namespace Shlinkio\Shlink\Installer\Config\Option\QrCode;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class DefaultSizeConfigOption extends BaseConfigOption
{
use ConfigOptionsValidatorsTrait;

private const MIN_SIZE = 50;
private const MAX_SIZE = 1000;

Expand All @@ -25,7 +23,7 @@ public function ask(StyleInterface $io, array $currentOptions): int
return $io->ask(
'What\'s the default size, in pixels, you want generated QR codes to have (50 to 1000)',
'300',
fn (mixed $value) => $this->validateNumberBetween($value, self::MIN_SIZE, self::MAX_SIZE),
fn (mixed $value) => ConfigOptionsValidator::validateNumberBetween($value, self::MIN_SIZE, self::MAX_SIZE),
);
}
}
6 changes: 2 additions & 4 deletions src/Config/Option/RabbitMq/RabbitMqPortConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace Shlinkio\Shlink\Installer\Config\Option\RabbitMq;

use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class RabbitMqPortConfigOption extends AbstractRabbitMqEnabledConfigOption
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'RABBITMQ_PORT';
Expand All @@ -22,7 +20,7 @@ public function ask(StyleInterface $io, array $currentOptions): int
return (int) $io->ask(
'RabbitMQ port',
$useSsl ? '5671' : '5672',
fn (mixed $value) => $this->validateNumberBetween($value, 1, 65535),
fn (mixed $value) => ConfigOptionsValidator::validateNumberBetween($value, 1, 65535),
);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Config/Option/Redirect/BaseUrlRedirectConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
namespace Shlinkio\Shlink\Installer\Config\Option\Redirect;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class BaseUrlRedirectConfigOption extends BaseConfigOption
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'DEFAULT_BASE_URL_REDIRECT';
Expand All @@ -23,7 +21,7 @@ public function ask(StyleInterface $io, array $currentOptions): ?string
'Custom URL to redirect to when a user hits Shlink\'s base URL (If no value is provided, the '
. 'user will see a default "404 not found" page)',
null,
[$this, 'validateUrl'],
ConfigOptionsValidator::validateUrl(...),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
namespace Shlinkio\Shlink\Installer\Config\Option\Redirect;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class InvalidShortUrlRedirectConfigOption extends BaseConfigOption
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'DEFAULT_INVALID_SHORT_URL_REDIRECT';
Expand All @@ -23,7 +21,7 @@ public function ask(StyleInterface $io, array $currentOptions): ?string
'Custom URL to redirect to when a user hits an invalid short URL (If no value is provided, the '
. 'user will see a default "404 not found" page)',
null,
[$this, 'validateUrl'],
ConfigOptionsValidator::validateUrl(...),
);
}
}
6 changes: 2 additions & 4 deletions src/Config/Option/Redirect/Regular404RedirectConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
namespace Shlinkio\Shlink\Installer\Config\Option\Redirect;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class Regular404RedirectConfigOption extends BaseConfigOption
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'DEFAULT_REGULAR_404_REDIRECT';
Expand All @@ -23,7 +21,7 @@ public function ask(StyleInterface $io, array $currentOptions): ?string
'Custom URL to redirect to when a user hits a not found URL other than an invalid short URL '
. '(If no value is provided, the user will see a default "404 not found" page)',
null,
[$this, 'validateUrl'],
ConfigOptionsValidator::validateUrl(...),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Option\DependentConfigOptionInterface;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Shlinkio\Shlink\Installer\Util\ArrayUtils;
use Symfony\Component\Console\Style\StyleInterface;

class RedirectCacheLifeTimeConfigOption extends BaseConfigOption implements DependentConfigOptionInterface
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'REDIRECT_CACHE_LIFETIME';
Expand All @@ -35,7 +33,7 @@ public function ask(StyleInterface $io, array $currentOptions): int
return $io->ask(
'How long (in seconds) do you want your redirects to be cached by visitors?',
'30',
[$this, 'validatePositiveNumber'],
ConfigOptionsValidator::validatePositiveNumber(...),
);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Config/Option/UrlShortener/ShortCodeLengthOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
namespace Shlinkio\Shlink\Installer\Config\Option\UrlShortener;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class ShortCodeLengthOption extends BaseConfigOption
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'DEFAULT_SHORT_CODES_LENGTH';
Expand All @@ -23,7 +21,7 @@ public function ask(StyleInterface $io, array $currentOptions): int
'What is the default length you want generated short codes to have? (You will still be able to override '
. 'this on every created short URL)',
'5',
fn ($value) => $this->validateNumberGreaterThan($value, 4),
fn ($value) => ConfigOptionsValidator::validateNumberGreaterThan($value, 4),
);
}
}
6 changes: 2 additions & 4 deletions src/Config/Option/Visit/VisitsThresholdConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
namespace Shlinkio\Shlink\Installer\Config\Option\Visit;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

class VisitsThresholdConfigOption extends BaseConfigOption
{
use ConfigOptionsValidatorsTrait;

public function getEnvVar(): string
{
return 'DELETE_SHORT_URL_THRESHOLD';
Expand All @@ -23,7 +21,7 @@ public function ask(StyleInterface $io, array $currentOptions): ?int
'What is the amount of visits from which the system will not allow short URLs to be deleted? Leave empty '
. 'to always allow deleting short URLs, no matter what',
null,
[$this, 'validateOptionalPositiveNumber'],
ConfigOptionsValidator::validateOptionalPositiveNumber(...),
);

return $result === null ? null : (int) $result;
Expand Down
6 changes: 2 additions & 4 deletions src/Config/Option/Worker/AbstractWorkerNumConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
namespace Shlinkio\Shlink\Installer\Config\Option\Worker;

use Shlinkio\Shlink\Installer\Config\Option\Server\AbstractAsyncRuntimeDependentConfigOption;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidatorsTrait;
use Shlinkio\Shlink\Installer\Config\Util\ConfigOptionsValidator;
use Symfony\Component\Console\Style\StyleInterface;

abstract class AbstractWorkerNumConfigOption extends AbstractAsyncRuntimeDependentConfigOption
{
use ConfigOptionsValidatorsTrait;

public function ask(StyleInterface $io, array $currentOptions): int
{
return $io->ask(
$this->getQuestionToAsk(),
'16',
fn ($value) => $this->validateNumberGreaterThan($value, $this->getMinimumValue()),
fn ($value) => ConfigOptionsValidator::validateNumberGreaterThan($value, $this->getMinimumValue()),
);
}

Expand Down
Loading
Loading