| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Endroid\QrCode\Writer; |
| 6 |
|
| 7 |
use Endroid\QrCode\Bacon\MatrixFactory; |
| 8 |
use Endroid\QrCode\Label\LabelInterface; |
| 9 |
use Endroid\QrCode\Logo\LogoInterface; |
| 10 |
use Endroid\QrCode\QrCodeInterface; |
| 11 |
use Endroid\QrCode\Writer\Result\DebugResult; |
| 12 |
use Endroid\QrCode\Writer\Result\ResultInterface; |
| 13 |
|
| 14 |
final class DebugWriter implements WriterInterface, ValidatingWriterInterface |
| 15 |
{ |
| 16 |
public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface |
| 17 |
{ |
| 18 |
$matrixFactory = new MatrixFactory(); |
| 19 |
$matrix = $matrixFactory->create($qrCode); |
| 20 |
|
| 21 |
return new DebugResult($matrix, $qrCode, $logo, $label, $options); |
| 22 |
} |
| 23 |
|
| 24 |
public function validateResult(ResultInterface $result, string $expectedData): void |
| 25 |
{ |
| 26 |
if (!$result instanceof DebugResult) { |
| 27 |
throw new \Exception('Unable to write logo: instance of DebugResult expected'); |
| 28 |
} |
| 29 |
|
| 30 |
$result->setValidateResult(true); |
| 31 |
} |
| 32 |
} |