mirror of
https://github.com/shlinkio/shlink.git
synced 2025-12-11 06:45:13 -06:00
Update to endroid/qr-code 5
This commit is contained in:
parent
58a3791a5c
commit
d01dc334d7
@ -21,7 +21,7 @@
|
|||||||
"cakephp/chronos": "^3.0.2",
|
"cakephp/chronos": "^3.0.2",
|
||||||
"doctrine/migrations": "^3.6",
|
"doctrine/migrations": "^3.6",
|
||||||
"doctrine/orm": "^3.0",
|
"doctrine/orm": "^3.0",
|
||||||
"endroid/qr-code": "^4.8",
|
"endroid/qr-code": "^5.0",
|
||||||
"friendsofphp/proxy-manager-lts": "^1.0",
|
"friendsofphp/proxy-manager-lts": "^1.0",
|
||||||
"geoip2/geoip2": "^3.0",
|
"geoip2/geoip2": "^3.0",
|
||||||
"guzzlehttp/guzzle": "^7.5",
|
"guzzlehttp/guzzle": "^7.5",
|
||||||
@ -42,7 +42,7 @@
|
|||||||
"pugx/shortid-php": "^1.1",
|
"pugx/shortid-php": "^1.1",
|
||||||
"ramsey/uuid": "^4.7",
|
"ramsey/uuid": "^4.7",
|
||||||
"shlinkio/doctrine-specification": "^2.1.1",
|
"shlinkio/doctrine-specification": "^2.1.1",
|
||||||
"shlinkio/shlink-common": "dev-main#762b3b8 as 6.0",
|
"shlinkio/shlink-common": "dev-main#b9a6bd5 as 6.0",
|
||||||
"shlinkio/shlink-config": "dev-main#a43b380 as 3.0",
|
"shlinkio/shlink-config": "dev-main#a43b380 as 3.0",
|
||||||
"shlinkio/shlink-event-dispatcher": "dev-main#aa9023c as 4.0",
|
"shlinkio/shlink-event-dispatcher": "dev-main#aa9023c as 4.0",
|
||||||
"shlinkio/shlink-importer": "dev-main#65a9a30 as 5.3",
|
"shlinkio/shlink-importer": "dev-main#65a9a30 as 5.3",
|
||||||
|
|||||||
@ -6,31 +6,25 @@ namespace Shlinkio\Shlink\Core\Action\Model;
|
|||||||
|
|
||||||
use Endroid\QrCode\Color\Color;
|
use Endroid\QrCode\Color\Color;
|
||||||
use Endroid\QrCode\Color\ColorInterface;
|
use Endroid\QrCode\Color\ColorInterface;
|
||||||
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
|
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||||
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelInterface;
|
use Endroid\QrCode\RoundBlockSizeMode;
|
||||||
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\PngWriter;
|
||||||
use Endroid\QrCode\Writer\SvgWriter;
|
use Endroid\QrCode\Writer\SvgWriter;
|
||||||
use Endroid\QrCode\Writer\WriterInterface;
|
use Endroid\QrCode\Writer\WriterInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Shlinkio\Shlink\Core\Options\QrCodeOptions;
|
use Shlinkio\Shlink\Core\Options\QrCodeOptions;
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
use function hexdec;
|
use function hexdec;
|
||||||
use function ltrim;
|
use function ltrim;
|
||||||
use function max;
|
use function max;
|
||||||
use function min;
|
use function min;
|
||||||
use function self;
|
|
||||||
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
|
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
|
||||||
use function strlen;
|
use function strlen;
|
||||||
use function strtolower;
|
use function strtolower;
|
||||||
use function substr;
|
use function substr;
|
||||||
use function trim;
|
use function trim;
|
||||||
|
|
||||||
use const Shlinkio\Shlink\DEFAULT_QR_CODE_BG_COLOR;
|
use const Shlinkio\Shlink\DEFAULT_QR_CODE_BG_COLOR;
|
||||||
use const Shlinkio\Shlink\DEFAULT_QR_CODE_COLOR;
|
use const Shlinkio\Shlink\DEFAULT_QR_CODE_COLOR;
|
||||||
|
|
||||||
@ -44,8 +38,8 @@ final class QrCodeParams
|
|||||||
public readonly int $size,
|
public readonly int $size,
|
||||||
public readonly int $margin,
|
public readonly int $margin,
|
||||||
public readonly WriterInterface $writer,
|
public readonly WriterInterface $writer,
|
||||||
public readonly ErrorCorrectionLevelInterface $errorCorrectionLevel,
|
public readonly ErrorCorrectionLevel $errorCorrectionLevel,
|
||||||
public readonly RoundBlockSizeModeInterface $roundBlockSizeMode,
|
public readonly RoundBlockSizeMode $roundBlockSizeMode,
|
||||||
public readonly ColorInterface $color,
|
public readonly ColorInterface $color,
|
||||||
public readonly ColorInterface $bgColor,
|
public readonly ColorInterface $bgColor,
|
||||||
) {
|
) {
|
||||||
@ -98,23 +92,23 @@ final class QrCodeParams
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function resolveErrorCorrection(array $query, QrCodeOptions $defaults): ErrorCorrectionLevelInterface
|
private static function resolveErrorCorrection(array $query, QrCodeOptions $defaults): ErrorCorrectionLevel
|
||||||
{
|
{
|
||||||
$errorCorrectionLevel = self::normalizeParam($query['errorCorrection'] ?? $defaults->errorCorrection);
|
$errorCorrectionLevel = self::normalizeParam($query['errorCorrection'] ?? $defaults->errorCorrection);
|
||||||
return match ($errorCorrectionLevel) {
|
return match ($errorCorrectionLevel) {
|
||||||
'h' => new ErrorCorrectionLevelHigh(),
|
'h' => ErrorCorrectionLevel::High,
|
||||||
'q' => new ErrorCorrectionLevelQuartile(),
|
'q' => ErrorCorrectionLevel::Quartile,
|
||||||
'm' => new ErrorCorrectionLevelMedium(),
|
'm' => ErrorCorrectionLevel::Medium,
|
||||||
default => new ErrorCorrectionLevelLow(), // 'l'
|
default => ErrorCorrectionLevel::Low, // 'l'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function resolveRoundBlockSize(array $query, QrCodeOptions $defaults): RoundBlockSizeModeInterface
|
private static function resolveRoundBlockSize(array $query, QrCodeOptions $defaults): RoundBlockSizeMode
|
||||||
{
|
{
|
||||||
$doNotRoundBlockSize = isset($query['roundBlockSize'])
|
$doNotRoundBlockSize = isset($query['roundBlockSize'])
|
||||||
? $query['roundBlockSize'] === 'false'
|
? $query['roundBlockSize'] === 'false'
|
||||||
: ! $defaults->roundBlockSize;
|
: ! $defaults->roundBlockSize;
|
||||||
return $doNotRoundBlockSize ? new RoundBlockSizeModeNone() : new RoundBlockSizeModeMargin();
|
return $doNotRoundBlockSize ? RoundBlockSizeMode::None : RoundBlockSizeMode::Margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function resolveColor(array $query, QrCodeOptions $defaults): ColorInterface
|
private static function resolveColor(array $query, QrCodeOptions $defaults): ColorInterface
|
||||||
@ -136,16 +130,16 @@ final class QrCodeParams
|
|||||||
try {
|
try {
|
||||||
if (strlen($hexColor) === 3) {
|
if (strlen($hexColor) === 3) {
|
||||||
return new Color(
|
return new Color(
|
||||||
hexdec(substr($hexColor, 0, 1) . substr($hexColor, 0, 1)),
|
(int) hexdec(substr($hexColor, 0, 1) . substr($hexColor, 0, 1)),
|
||||||
hexdec(substr($hexColor, 1, 1) . substr($hexColor, 1, 1)),
|
(int) hexdec(substr($hexColor, 1, 1) . substr($hexColor, 1, 1)),
|
||||||
hexdec(substr($hexColor, 2, 1) . substr($hexColor, 2, 1)),
|
(int) hexdec(substr($hexColor, 2, 1) . substr($hexColor, 2, 1)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Color(
|
return new Color(
|
||||||
hexdec(substr($hexColor, 0, 2)),
|
(int) hexdec(substr($hexColor, 0, 2)),
|
||||||
hexdec(substr($hexColor, 2, 2)),
|
(int) hexdec(substr($hexColor, 2, 2)),
|
||||||
hexdec(substr($hexColor, 4, 2)),
|
(int) hexdec(substr($hexColor, 4, 2)),
|
||||||
);
|
);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
// If a non-hex value was provided and an error occurs, fall back to the default color.
|
// If a non-hex value was provided and an error occurs, fall back to the default color.
|
||||||
|
|||||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace Shlinkio\Shlink\Core\Action;
|
namespace Shlinkio\Shlink\Core\Action;
|
||||||
|
|
||||||
use Endroid\QrCode\Builder\Builder;
|
use Endroid\QrCode\Builder\Builder;
|
||||||
use Endroid\QrCode\Color\Color;
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user