Allow QR code logo to be individually disabled

This commit is contained in:
Alejandro Celaya
2024-12-18 08:53:28 +01:00
parent 736e09adfe
commit 6ad8b03850
5 changed files with 34 additions and 14 deletions

View File

@@ -28,20 +28,21 @@ use function trim;
use const Shlinkio\Shlink\DEFAULT_QR_CODE_BG_COLOR;
use const Shlinkio\Shlink\DEFAULT_QR_CODE_COLOR;
final class QrCodeParams
final readonly class QrCodeParams
{
private const int MIN_SIZE = 50;
private const int MAX_SIZE = 1000;
private const array SUPPORTED_FORMATS = ['png', 'svg'];
private function __construct(
public readonly int $size,
public readonly int $margin,
public readonly WriterInterface $writer,
public readonly ErrorCorrectionLevel $errorCorrectionLevel,
public readonly RoundBlockSizeMode $roundBlockSizeMode,
public readonly ColorInterface $color,
public readonly ColorInterface $bgColor,
public int $size,
public int $margin,
public WriterInterface $writer,
public ErrorCorrectionLevel $errorCorrectionLevel,
public RoundBlockSizeMode $roundBlockSizeMode,
public ColorInterface $color,
public ColorInterface $bgColor,
public bool $disableLogo,
) {
}
@@ -57,6 +58,7 @@ final class QrCodeParams
roundBlockSizeMode: self::resolveRoundBlockSize($query, $defaults),
color: self::resolveColor($query, $defaults),
bgColor: self::resolveBackgroundColor($query, $defaults),
disableLogo: isset($query['logo']) && $query['logo'] === 'disable',
);
}

View File

@@ -60,7 +60,7 @@ readonly class QrCodeAction implements MiddlewareInterface
private function buildQrCode(Builder $qrCodeBuilder, QrCodeParams $params): ResultInterface
{
$logoUrl = $this->options->logoUrl;
if ($logoUrl === null) {
if ($logoUrl === null || $params->disableLogo) {
return $qrCodeBuilder->build();
}