diff --git a/composer.json b/composer.json index e985843e..b1badf18 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "pugx/shortid-php": "^0.7", "ramsey/uuid": "^3.9", "rlanvin/php-ip": "3.0.0-rc2", - "shlinkio/shlink-common": "dev-main#2f3ac05 as 4.2", + "shlinkio/shlink-common": "dev-main#7cc36a6 as 4.2", "shlinkio/shlink-config": "^1.4", "shlinkio/shlink-event-dispatcher": "dev-main#3925299 as 2.3", "shlinkio/shlink-importer": "dev-main#d099072 as 2.5", diff --git a/config/autoload/qr-codes.global.php b/config/autoload/qr-codes.global.php index 1cf6fecb..5f528620 100644 --- a/config/autoload/qr-codes.global.php +++ b/config/autoload/qr-codes.global.php @@ -7,6 +7,7 @@ use function Shlinkio\Shlink\Common\env; use const Shlinkio\Shlink\DEFAULT_QR_CODE_ERROR_CORRECTION; use const Shlinkio\Shlink\DEFAULT_QR_CODE_FORMAT; use const Shlinkio\Shlink\DEFAULT_QR_CODE_MARGIN; +use const Shlinkio\Shlink\DEFAULT_QR_CODE_ROUND_BLOCK_SIZE; use const Shlinkio\Shlink\DEFAULT_QR_CODE_SIZE; return [ @@ -16,6 +17,7 @@ return [ 'margin' => (int) env('DEFAULT_QR_CODE_MARGIN', DEFAULT_QR_CODE_MARGIN), 'format' => env('DEFAULT_QR_CODE_FORMAT', DEFAULT_QR_CODE_FORMAT), 'error_correction' => env('DEFAULT_QR_CODE_ERROR_CORRECTION', DEFAULT_QR_CODE_ERROR_CORRECTION), + 'round_block_size' => (bool) env('DEFAULT_QR_CODE_ROUND_BLOCK_SIZE', DEFAULT_QR_CODE_ROUND_BLOCK_SIZE), ], ]; diff --git a/config/constants.php b/config/constants.php index 6c7aa09e..8171cd66 100644 --- a/config/constants.php +++ b/config/constants.php @@ -18,4 +18,5 @@ const DEFAULT_QR_CODE_SIZE = 300; const DEFAULT_QR_CODE_MARGIN = 0; const DEFAULT_QR_CODE_FORMAT = 'png'; const DEFAULT_QR_CODE_ERROR_CORRECTION = 'l'; +const DEFAULT_QR_CODE_ROUND_BLOCK_SIZE = true; const MIN_TASK_WORKERS = 4; diff --git a/module/Core/src/Action/Model/QrCodeParams.php b/module/Core/src/Action/Model/QrCodeParams.php index 0e889c32..47fb82d4 100644 --- a/module/Core/src/Action/Model/QrCodeParams.php +++ b/module/Core/src/Action/Model/QrCodeParams.php @@ -9,6 +9,9 @@ use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelInterface; use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow; use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium; use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelQuartile; +use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeInterface; +use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin; +use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeNone; use Endroid\QrCode\Writer\PngWriter; use Endroid\QrCode\Writer\SvgWriter; use Endroid\QrCode\Writer\WriterInterface; @@ -31,6 +34,7 @@ final class QrCodeParams private int $margin, private WriterInterface $writer, private ErrorCorrectionLevelInterface $errorCorrectionLevel, + private RoundBlockSizeModeInterface $roundBlockSizeMode, ) { } @@ -43,6 +47,7 @@ final class QrCodeParams self::resolveMargin($query, $defaults), self::resolveWriter($query, $defaults), self::resolveErrorCorrection($query, $defaults), + self::resolveRoundBlockSize($query, $defaults), ); } @@ -90,6 +95,12 @@ final class QrCodeParams }; } + private static function resolveRoundBlockSize(array $query, QrCodeOptions $defaults): RoundBlockSizeModeInterface + { + $doNotRoundBlockSize = ($query['roundBlockSize'] ?? null) === 'false' || ! $defaults->roundBlockSize(); + return $doNotRoundBlockSize ? new RoundBlockSizeModeNone() : new RoundBlockSizeModeMargin(); + } + private static function normalizeParam(string $param): string { return strtolower(trim($param)); @@ -114,4 +125,9 @@ final class QrCodeParams { return $this->errorCorrectionLevel; } + + public function roundBlockSizeMode(): RoundBlockSizeModeInterface + { + return $this->roundBlockSizeMode; + } } diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index f8d2e275..7772a5c8 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -45,7 +45,8 @@ class QrCodeAction implements MiddlewareInterface ->size($params->size()) ->margin($params->margin()) ->writer($params->writer()) - ->errorCorrectionLevel($params->errorCorrectionLevel()); + ->errorCorrectionLevel($params->errorCorrectionLevel()) + ->roundBlockSizeMode($params->roundBlockSizeMode()); return new QrCodeResponse($qrCodeBuilder->build()); } diff --git a/module/Core/src/Options/QrCodeOptions.php b/module/Core/src/Options/QrCodeOptions.php index 80d6e456..3dfc9a53 100644 --- a/module/Core/src/Options/QrCodeOptions.php +++ b/module/Core/src/Options/QrCodeOptions.php @@ -9,6 +9,7 @@ use Laminas\Stdlib\AbstractOptions; use const Shlinkio\Shlink\DEFAULT_QR_CODE_ERROR_CORRECTION; use const Shlinkio\Shlink\DEFAULT_QR_CODE_FORMAT; use const Shlinkio\Shlink\DEFAULT_QR_CODE_MARGIN; +use const Shlinkio\Shlink\DEFAULT_QR_CODE_ROUND_BLOCK_SIZE; use const Shlinkio\Shlink\DEFAULT_QR_CODE_SIZE; class QrCodeOptions extends AbstractOptions @@ -17,6 +18,7 @@ class QrCodeOptions extends AbstractOptions private int $margin = DEFAULT_QR_CODE_MARGIN; private string $format = DEFAULT_QR_CODE_FORMAT; private string $errorCorrection = DEFAULT_QR_CODE_ERROR_CORRECTION; + private bool $roundBlockSize = DEFAULT_QR_CODE_ROUND_BLOCK_SIZE; public function size(): int { @@ -57,4 +59,14 @@ class QrCodeOptions extends AbstractOptions { $this->errorCorrection = $errorCorrection; } + + public function roundBlockSize(): bool + { + return $this->roundBlockSize; + } + + protected function setRoundBlockSize(bool $roundBlockSize): void + { + $this->roundBlockSize = $roundBlockSize; + } }