Skip to content

Commit 92487ac

Browse files
cliffordvickreyClifford Vickrey
and
Clifford Vickrey
authored
add support for endroid/qr-code version 6 (#140)
* add support for endroid/qr-code version 6 * add endroid v6 to github workflows * remove negative conditional (endroid-related) --------- Co-authored-by: Clifford Vickrey <[email protected]>
1 parent ab4c330 commit 92487ac

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/test-endroid.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
php-version: ['8.2', '8.3']
14-
endroid-version: ["^3","^4","^5"]
14+
endroid-version: ["^3","^4","^5","^6"]
1515

1616
steps:
1717
- uses: actions/checkout@v4

lib/Providers/Qr/EndroidQrCodeProvider.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ class EndroidQrCodeProvider implements IQRCodeProvider
2828

2929
protected $endroid5 = false;
3030

31+
protected $endroid6 = false;
32+
3133
public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H')
3234
{
33-
$this->endroid4 = method_exists(QrCode::class, 'create');
3435
$this->endroid5 = enum_exists(ErrorCorrectionLevel::class);
36+
$this->endroid6 = $this->endroid5 && !method_exists(QrCode::class, 'setSize');
37+
$this->endroid4 = $this->endroid6 || method_exists(QrCode::class, 'create');
3538

3639
$this->bgcolor = $this->handleColor($bgcolor);
3740
$this->color = $this->handleColor($color);
@@ -56,14 +59,24 @@ public function getQRCodeImage(string $qrText, int $size): string
5659

5760
protected function qrCodeInstance(string $qrText, int $size): QrCode
5861
{
62+
if ($this->endroid6) {
63+
return new QrCode(
64+
data: $qrText,
65+
errorCorrectionLevel: $this->errorcorrectionlevel,
66+
size: $size,
67+
margin: $this->margin,
68+
foregroundColor: $this->color,
69+
backgroundColor: $this->bgcolor
70+
);
71+
}
72+
5973
$qrCode = new QrCode($qrText);
6074
$qrCode->setSize($size);
6175

6276
$qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel);
6377
$qrCode->setMargin($this->margin);
6478
$qrCode->setBackgroundColor($this->bgcolor);
6579
$qrCode->setForegroundColor($this->color);
66-
6780
return $qrCode;
6881
}
6982

0 commit comments

Comments
 (0)