Merge pull request #2233 from acelaya-forks/feature/endroid-qr-code-6

Update to endroid/qr-code 6.0
This commit is contained in:
Alejandro Celaya 2024-10-22 09:06:30 +02:00 committed by GitHub
commit 549a8d8837
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 16 deletions

View File

@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* *Nothing*
### Changed
* Run RoadRunner in docker with `exec` to ensure signals are properly handled.
* [#2232](https://github.com/shlinkio/shlink/issues/2232) Run RoadRunner in docker with `exec` to ensure signals are properly handled.
* [#2231](https://github.com/shlinkio/shlink/issues/2231) Update to `endroid/qr-code` 6.0.
### Deprecated
* *Nothing*

View File

@ -23,7 +23,7 @@
"doctrine/dbal": "^4.1",
"doctrine/migrations": "^3.6",
"doctrine/orm": "^3.2",
"endroid/qr-code": "^5.0",
"endroid/qr-code": "^6.0",
"friendsofphp/proxy-manager-lts": "^1.0",
"geoip2/geoip2": "^3.0",
"guzzlehttp/guzzle": "^7.5",
@ -44,7 +44,7 @@
"pagerfanta/core": "^3.8",
"ramsey/uuid": "^4.7",
"shlinkio/doctrine-specification": "^2.1.1",
"shlinkio/shlink-common": "^6.3",
"shlinkio/shlink-common": "dev-main#e0c872c as 6.4",
"shlinkio/shlink-config": "^3.2.1",
"shlinkio/shlink-event-dispatcher": "^4.1",
"shlinkio/shlink-importer": "^5.3.2",

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Action;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Writer\Result\ResultInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface;
@ -42,22 +43,30 @@ readonly class QrCodeAction implements MiddlewareInterface
}
$params = QrCodeParams::fromRequest($request, $this->options);
$qrCodeBuilder = Builder::create()
->data($this->stringifier->stringify($shortUrl))
->size($params->size)
->margin($params->margin)
->writer($params->writer)
->errorCorrectionLevel($params->errorCorrectionLevel)
->roundBlockSizeMode($params->roundBlockSizeMode)
->foregroundColor($params->color)
->backgroundColor($params->bgColor);
$qrCodeBuilder = new Builder(
writer: $params->writer,
data: $this->stringifier->stringify($shortUrl),
errorCorrectionLevel: $params->errorCorrectionLevel,
size: $params->size,
margin: $params->margin,
roundBlockSizeMode: $params->roundBlockSizeMode,
foregroundColor: $params->color,
backgroundColor: $params->bgColor,
);
return new QrCodeResponse($this->buildQrCode($qrCodeBuilder, $params));
}
private function buildQrCode(Builder $qrCodeBuilder, QrCodeParams $params): ResultInterface
{
$logoUrl = $this->options->logoUrl;
if ($logoUrl !== null) {
$qrCodeBuilder->logoPath($logoUrl)
->logoResizeToHeight((int) ($params->size / 4));
if ($logoUrl === null) {
return $qrCodeBuilder->build();
}
return new QrCodeResponse($qrCodeBuilder->build());
return $qrCodeBuilder->build(
logoPath: $logoUrl,
logoResizeToHeight: (int) ($params->size / 4),
);
}
}