mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-19 01:52:32 +00:00
use http_build_query instead of sprintf to improve readability
This commit is contained in:
@@ -23,12 +23,14 @@ class GoogleChartsQrCodeProvider extends BaseHTTPQRCodeProvider
|
||||
|
||||
public function getUrl(string $qrtext, int $size): string
|
||||
{
|
||||
return sprintf(
|
||||
'https://chart.googleapis.com/chart?chs=%1$sx%1$s&chld=%2$s&cht=qr&choe=%3$s&chl=%4$s',
|
||||
$size,
|
||||
urlencode(strtoupper($this->errorcorrectionlevel) . '|' . $this->margin),
|
||||
$this->encoding,
|
||||
rawurlencode($qrtext)
|
||||
$queryParameters = array(
|
||||
'chs' => $size . 'x' . $size,
|
||||
'chld' => strtoupper($this->errorcorrectionlevel) . '|' . $this->margin,
|
||||
'cht' => 'qr',
|
||||
'choe' => $this->encoding,
|
||||
'chl' => $qrtext,
|
||||
);
|
||||
|
||||
return 'https://chart.googleapis.com/chart?' . http_build_query($queryParameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,13 @@ class ImageChartsQRCodeProvider extends BaseHTTPQRCodeProvider
|
||||
|
||||
public function getUrl(string $qrtext, int $size): string
|
||||
{
|
||||
return sprintf(
|
||||
'https://image-charts.com/chart?cht=qr&chs=%1$dx%1$d&chld=%2$s|%3$s&chl=%4$s',
|
||||
ceil($size / 2),
|
||||
$this->errorcorrectionlevel,
|
||||
$this->margin,
|
||||
rawurlencode($qrtext)
|
||||
$queryParameters = array(
|
||||
'cht' => 'qr',
|
||||
'chs' => ceil($size / 2) . 'x' . ceil($size / 2),
|
||||
'chld' => $this->errorcorrectionlevel . '|' . $this->margin,
|
||||
'chl' => $qrtext,
|
||||
);
|
||||
|
||||
return 'https://image-charts.com/chart?' . http_build_query($queryParameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,17 +38,18 @@ class QRServerProvider extends BaseHTTPQRCodeProvider
|
||||
|
||||
public function getUrl(string $qrtext, int $size): string
|
||||
{
|
||||
return sprintf(
|
||||
'https://api.qrserver.com/v1/create-qr-code/?size=%1$sx%1$s&ecc=%2$s&margin=%3$s&qzone=%4$s&bgcolor=%5$s&color=%6$s&format=%7$s&data=%8$s',
|
||||
$size,
|
||||
strtoupper($this->errorcorrectionlevel),
|
||||
$this->margin,
|
||||
$this->qzone,
|
||||
$this->decodeColor($this->bgcolor),
|
||||
$this->decodeColor($this->color),
|
||||
strtolower($this->format),
|
||||
rawurlencode($qrtext)
|
||||
$queryParameters = array(
|
||||
'size' => $size . 'x' . $size,
|
||||
'ecc' => strtoupper($this->errorcorrectionlevel),
|
||||
'margin' => $this->margin,
|
||||
'qzone' => $this->qzone,
|
||||
'bgcolor' => $this->decodeColor($this->bgcolor),
|
||||
'color' => $this->decodeColor($this->color),
|
||||
'format' => strtolower($this->format),
|
||||
'data' => $qrtext,
|
||||
);
|
||||
|
||||
return 'https://api.qrserver.com/v1/create-qr-code/?' . http_build_query($queryParameters);
|
||||
}
|
||||
|
||||
private function decodeColor(string $value): string
|
||||
|
||||
@@ -34,14 +34,15 @@ class QRicketProvider extends BaseHTTPQRCodeProvider
|
||||
|
||||
public function getUrl(string $qrtext, int $size): string
|
||||
{
|
||||
return sprintf(
|
||||
'http://qrickit.com/api/qr?qrsize=%s&e=%s&bgdcolor=%s&fgdcolor=%s&t=%s&d=%s',
|
||||
$size,
|
||||
strtolower($this->errorcorrectionlevel),
|
||||
$this->bgcolor,
|
||||
$this->color,
|
||||
strtolower($this->format),
|
||||
rawurlencode($qrtext)
|
||||
$queryParameters = array(
|
||||
'qrsize' => $size,
|
||||
'e' => strtolower($this->errorcorrectionlevel),
|
||||
'bgdcolor' => $this->bgcolor,
|
||||
'fgdcolor' => $this->color,
|
||||
't' => strtolower($this->format),
|
||||
'd' => $qrtext,
|
||||
);
|
||||
|
||||
return 'http://qrickit.com/api/qr?' . http_build_query($queryParameters);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user