TaoLer/vendor/endroid/qr-code/src/Writer/DebugWriter.php

33 lines
1.0 KiB
PHP
Raw Normal View History

2022-08-02 21:13:36 +08:00
<?php
declare(strict_types=1);
namespace Endroid\QrCode\Writer;
2022-11-20 21:56:09 +08:00
use Endroid\QrCode\Bacon\MatrixFactory;
2022-08-02 21:13:36 +08:00
use Endroid\QrCode\Label\LabelInterface;
use Endroid\QrCode\Logo\LogoInterface;
use Endroid\QrCode\QrCodeInterface;
use Endroid\QrCode\Writer\Result\DebugResult;
use Endroid\QrCode\Writer\Result\ResultInterface;
final class DebugWriter implements WriterInterface, ValidatingWriterInterface
{
public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface
{
2022-11-20 21:56:09 +08:00
$matrixFactory = new MatrixFactory();
$matrix = $matrixFactory->create($qrCode);
return new DebugResult($matrix, $qrCode, $logo, $label, $options);
2022-08-02 21:13:36 +08:00
}
public function validateResult(ResultInterface $result, string $expectedData): void
{
if (!$result instanceof DebugResult) {
throw new \Exception('Unable to write logo: instance of DebugResult expected');
}
$result->setValidateResult(true);
}
}