Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for endroid/qr-code version 6 #140

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-endroid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
php-version: ['8.2', '8.3']
endroid-version: ["^3","^4","^5"]
endroid-version: ["^3","^4","^5","^6"]

steps:
- uses: actions/checkout@v4
Expand Down
31 changes: 22 additions & 9 deletions lib/Providers/Qr/EndroidQrCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ class EndroidQrCodeProvider implements IQRCodeProvider

protected $endroid5 = false;

protected $endroid6 = false;

public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H')
{
$this->endroid4 = method_exists(QrCode::class, 'create');
$this->endroid5 = enum_exists(ErrorCorrectionLevel::class);
$this->endroid6 = $this->endroid5 && !method_exists(QrCode::class, 'setSize');
$this->endroid4 = $this->endroid6 || method_exists(QrCode::class, 'create');

$this->bgcolor = $this->handleColor($bgcolor);
$this->color = $this->handleColor($color);
Expand All @@ -56,15 +59,25 @@ public function getQRCodeImage(string $qrText, int $size): string

protected function qrCodeInstance(string $qrText, int $size): QrCode
{
$qrCode = new QrCode($qrText);
$qrCode->setSize($size);

$qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel);
$qrCode->setMargin($this->margin);
$qrCode->setBackgroundColor($this->bgcolor);
$qrCode->setForegroundColor($this->color);
if (!$this->endroid6) {
NicolasCARPi marked this conversation as resolved.
Show resolved Hide resolved
$qrCode = new QrCode($qrText);
$qrCode->setSize($size);

$qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel);
$qrCode->setMargin($this->margin);
$qrCode->setBackgroundColor($this->bgcolor);
$qrCode->setForegroundColor($this->color);
return $qrCode;
}

return $qrCode;
return new QrCode(
data: $qrText,
errorCorrectionLevel: $this->errorcorrectionlevel,
size: $size,
margin: $this->margin,
foregroundColor: $this->color,
backgroundColor: $this->bgcolor
);
}

private function handleColor(string $color): Color|array
Expand Down