vendor and env first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Bacon;
|
||||
|
||||
use BaconQrCode\Common\ErrorCorrectionLevel as BaconErrorCorrectionLevel;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
|
||||
final readonly class ErrorCorrectionLevelConverter
|
||||
{
|
||||
public static function convertToBaconErrorCorrectionLevel(ErrorCorrectionLevel $errorCorrectionLevel): BaconErrorCorrectionLevel
|
||||
{
|
||||
return match ($errorCorrectionLevel) {
|
||||
ErrorCorrectionLevel::Low => BaconErrorCorrectionLevel::valueOf('L'),
|
||||
ErrorCorrectionLevel::Medium => BaconErrorCorrectionLevel::valueOf('M'),
|
||||
ErrorCorrectionLevel::Quartile => BaconErrorCorrectionLevel::valueOf('Q'),
|
||||
ErrorCorrectionLevel::High => BaconErrorCorrectionLevel::valueOf('H'),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Bacon;
|
||||
|
||||
use BaconQrCode\Encoder\Encoder;
|
||||
use Endroid\QrCode\Matrix\Matrix;
|
||||
use Endroid\QrCode\Matrix\MatrixFactoryInterface;
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
use Endroid\QrCode\QrCodeInterface;
|
||||
|
||||
final readonly class MatrixFactory implements MatrixFactoryInterface
|
||||
{
|
||||
public function create(QrCodeInterface $qrCode): MatrixInterface
|
||||
{
|
||||
$baconErrorCorrectionLevel = ErrorCorrectionLevelConverter::convertToBaconErrorCorrectionLevel($qrCode->getErrorCorrectionLevel());
|
||||
$baconMatrix = Encoder::encode($qrCode->getData(), $baconErrorCorrectionLevel, strval($qrCode->getEncoding()))->getMatrix();
|
||||
|
||||
$blockValues = [];
|
||||
$columnCount = $baconMatrix->getWidth();
|
||||
$rowCount = $baconMatrix->getHeight();
|
||||
for ($rowIndex = 0; $rowIndex < $rowCount; ++$rowIndex) {
|
||||
$blockValues[$rowIndex] = [];
|
||||
for ($columnIndex = 0; $columnIndex < $columnCount; ++$columnIndex) {
|
||||
$blockValues[$rowIndex][$columnIndex] = $baconMatrix->get($columnIndex, $rowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return new Matrix($blockValues, $qrCode->getSize(), $qrCode->getMargin(), $qrCode->getRoundBlockSizeMode());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user