Skip to content

Commit

Permalink
Merge pull request #232 from sprain/endroid-5
Browse files Browse the repository at this point in the history
Add support for Endroid 5
  • Loading branch information
sprain committed Oct 4, 2023
2 parents 2820c82 + 51888c0 commit f3db31c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"symfony/validator": "^4.4|^5.0|^6.0",
"symfony/intl": "^4.4|^5.0|^6.0",
"kmukku/php-iso11649": "^1.5",
"endroid/qr-code": "^4.4.4",
"endroid/qr-code": "^4.4.4|^5.0",
"symfony/polyfill-intl-icu": "^1.23"
},
"require-dev": {
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 23 additions & 8 deletions src/QrCode/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Sprain\SwissQrBill\QrCode;

use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\Logo\Logo;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge;
use Endroid\QrCode\QrCode as BaseQrCode;
use Endroid\QrCode\RoundBlockSizeMode;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\Result\ResultInterface;
use Endroid\QrCode\Writer\SvgWriter;
Expand Down Expand Up @@ -42,12 +42,27 @@ public static function create(string $data, string $fileFormat = null): self

private function __construct(string $data, string $fileFormat)
{
$this->qrCode = BaseQrCode::create($data)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelMedium())
->setSize(self::PX_QR_CODE)
->setMargin(0)
->setRoundBlockSizeMode(new RoundBlockSizeModeEnlarge());
if (class_exists(ErrorCorrectionLevel\ErrorCorrectionLevelMedium::class)) {
// Endroid 4.x
$this->qrCode = BaseQrCode::create($data)
->setEncoding(new Encoding('UTF-8'))
/** @phpstan-ignore-next-line as it throws error if Endroid 5 is installed */
->setErrorCorrectionLevel(new ErrorCorrectionLevel\ErrorCorrectionLevelMedium())
->setSize(self::PX_QR_CODE)
->setMargin(0)
/** @phpstan-ignore-next-line as it throws error if Endroid 5 is installed */
->setRoundBlockSizeMode(new RoundBlockSizeMode\RoundBlockSizeModeEnlarge());
} else {
// Endroid 5.x
$this->qrCode = BaseQrCode::create($data)
->setEncoding(new Encoding('UTF-8'))
/** @phpstan-ignore-next-line as it throws error if Endroid 4 is installed */
->setErrorCorrectionLevel(ErrorCorrectionLevel::Medium)
->setSize(self::PX_QR_CODE)
->setMargin(0)
/** @phpstan-ignore-next-line as it throws error if Endroid 4 is installed */
->setRoundBlockSizeMode(RoundBlockSizeMode::Enlarge);
}

$this->qrCodeLogo = Logo::create(self::SWISS_CROSS_LOGO_FILE)
->setResizeToWidth(self::PX_SWISS_CROSS);
Expand Down

0 comments on commit f3db31c

Please sign in to comment.