| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Endroid\QrCode\Bacon; |
| 6 |
|
| 7 |
use BaconQrCode\Encoder\Encoder; |
| 8 |
use Endroid\QrCode\Matrix\Matrix; |
| 9 |
use Endroid\QrCode\Matrix\MatrixFactoryInterface; |
| 10 |
use Endroid\QrCode\Matrix\MatrixInterface; |
| 11 |
use Endroid\QrCode\QrCodeInterface; |
| 12 |
|
| 13 |
final class MatrixFactory implements MatrixFactoryInterface |
| 14 |
{ |
| 15 |
public function create(QrCodeInterface $qrCode): MatrixInterface |
| 16 |
{ |
| 17 |
$baconErrorCorrectionLevel = ErrorCorrectionLevelConverter::convertToBaconErrorCorrectionLevel($qrCode->getErrorCorrectionLevel()); |
| 18 |
$baconMatrix = Encoder::encode($qrCode->getData(), $baconErrorCorrectionLevel, strval($qrCode->getEncoding()))->getMatrix(); |
| 19 |
|
| 20 |
$blockValues = []; |
| 21 |
$columnCount = $baconMatrix->getWidth(); |
| 22 |
$rowCount = $baconMatrix->getHeight(); |
| 23 |
for ($rowIndex = 0; $rowIndex < $rowCount; ++$rowIndex) { |
| 24 |
$blockValues[$rowIndex] = []; |
| 25 |
for ($columnIndex = 0; $columnIndex < $columnCount; ++$columnIndex) { |
| 26 |
$blockValues[$rowIndex][$columnIndex] = $baconMatrix->get($columnIndex, $rowIndex); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
return new Matrix($blockValues, $qrCode->getSize(), $qrCode->getMargin(), $qrCode->getRoundBlockSizeMode()); |
| 31 |
} |
| 32 |
} |