mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-25 02:10:18 -06:00
This commit is contained in:
parent
74108a19e5
commit
a72dc16d85
@ -29,7 +29,17 @@ return [
|
||||
],
|
||||
[
|
||||
'name' => Action\QrCodeAction::class,
|
||||
'path' => '/{shortCode}/qr-code[/{size:[0-9]+}]',
|
||||
'path' => '/{shortCode}/qr-code',
|
||||
'middleware' => [
|
||||
Action\QrCodeAction::class,
|
||||
],
|
||||
'allowed_methods' => [RequestMethod::METHOD_GET],
|
||||
],
|
||||
|
||||
// Deprecated
|
||||
[
|
||||
'name' => 'old_' . Action\QrCodeAction::class,
|
||||
'path' => '/{shortCode}/qr-code/{size:[0-9]+}',
|
||||
'middleware' => [
|
||||
Action\QrCodeAction::class,
|
||||
],
|
||||
|
@ -48,11 +48,15 @@ class QrCodeAction implements MiddlewareInterface
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
$query = $request->getQueryParams();
|
||||
// Size attribute is deprecated
|
||||
$size = $this->normalizeSize($request->getAttribute('size', $query['size'] ?? self::DEFAULT_SIZE));
|
||||
|
||||
$qrCode = new QrCode($shortUrl->toString($this->domainConfig));
|
||||
$qrCode->setSize($this->getSizeParam($request));
|
||||
$qrCode->setSize($size);
|
||||
$qrCode->setMargin(0);
|
||||
|
||||
$format = $request->getQueryParams()['format'] ?? 'png';
|
||||
$format = $query['format'] ?? 'png';
|
||||
if ($format === 'svg') {
|
||||
$qrCode->setWriter(new SvgWriter());
|
||||
}
|
||||
@ -60,9 +64,8 @@ class QrCodeAction implements MiddlewareInterface
|
||||
return new QrCodeResponse($qrCode);
|
||||
}
|
||||
|
||||
private function getSizeParam(Request $request): int
|
||||
private function normalizeSize(int $size): int
|
||||
{
|
||||
$size = (int) $request->getAttribute('size', self::DEFAULT_SIZE);
|
||||
if ($size < self::MIN_SIZE) {
|
||||
return self::MIN_SIZE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user