| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Endroid\QrCode\Writer\Result; |
| 6 |
|
| 7 |
use Endroid\QrCode\Label\LabelInterface; |
| 8 |
use Endroid\QrCode\Logo\LogoInterface; |
| 9 |
use Endroid\QrCode\Matrix\MatrixInterface; |
| 10 |
use Endroid\QrCode\QrCodeInterface; |
| 11 |
|
| 12 |
final class DebugResult extends AbstractResult |
| 13 |
{ |
| 14 |
private bool $validateResult = false; |
| 15 |
|
| 16 |
public function __construct( |
| 17 |
MatrixInterface $matrix, |
| 18 |
private readonly QrCodeInterface $qrCode, |
| 19 |
private readonly LogoInterface|null $logo = null, |
| 20 |
private readonly LabelInterface|null $label = null, |
| 21 |
/** @var array<string, mixed> $options */ |
| 22 |
private readonly array $options = [] |
| 23 |
) { |
| 24 |
parent::__construct($matrix); |
| 25 |
} |
| 26 |
|
| 27 |
public function setValidateResult(bool $validateResult): void |
| 28 |
{ |
| 29 |
$this->validateResult = $validateResult; |
| 30 |
} |
| 31 |
|
| 32 |
public function getString(): string |
| 33 |
{ |
| 34 |
$debugLines = []; |
| 35 |
|
| 36 |
$debugLines[] = 'Data: '.$this->qrCode->getData(); |
| 37 |
$debugLines[] = 'Encoding: '.$this->qrCode->getEncoding(); |
| 38 |
$debugLines[] = 'Error Correction Level: '.get_class($this->qrCode->getErrorCorrectionLevel()); |
| 39 |
$debugLines[] = 'Size: '.$this->qrCode->getSize(); |
| 40 |
$debugLines[] = 'Margin: '.$this->qrCode->getMargin(); |
| 41 |
$debugLines[] = 'Round block size mode: '.get_class($this->qrCode->getRoundBlockSizeMode()); |
| 42 |
$debugLines[] = 'Foreground color: ['.implode(', ', $this->qrCode->getForegroundColor()->toArray()).']'; |
| 43 |
$debugLines[] = 'Background color: ['.implode(', ', $this->qrCode->getBackgroundColor()->toArray()).']'; |
| 44 |
|
| 45 |
foreach ($this->options as $key => $value) { |
| 46 |
$debugLines[] = 'Writer option: '.$key.': '.$value; |
| 47 |
} |
| 48 |
|
| 49 |
if (isset($this->logo)) { |
| 50 |
$debugLines[] = 'Logo path: '.$this->logo->getPath(); |
| 51 |
$debugLines[] = 'Logo resize to width: '.$this->logo->getResizeToWidth(); |
| 52 |
$debugLines[] = 'Logo resize to height: '.$this->logo->getResizeToHeight(); |
| 53 |
$debugLines[] = 'Logo punchout background: '.($this->logo->getPunchoutBackground() ? 'true' : 'false'); |
| 54 |
} |
| 55 |
|
| 56 |
if (isset($this->label)) { |
| 57 |
$debugLines[] = 'Label text: '.$this->label->getText(); |
| 58 |
$debugLines[] = 'Label font path: '.$this->label->getFont()->getPath(); |
| 59 |
$debugLines[] = 'Label font size: '.$this->label->getFont()->getSize(); |
| 60 |
$debugLines[] = 'Label alignment: '.get_class($this->label->getAlignment()); |
| 61 |
$debugLines[] = 'Label margin: ['.implode(', ', $this->label->getMargin()->toArray()).']'; |
| 62 |
$debugLines[] = 'Label text color: ['.implode(', ', $this->label->getTextColor()->toArray()).']'; |
| 63 |
} |
| 64 |
|
| 65 |
$debugLines[] = 'Validate result: '.($this->validateResult ? 'true' : 'false'); |
| 66 |
|
| 67 |
return implode("\n", $debugLines); |
| 68 |
} |
| 69 |
|
| 70 |
public function getMimeType(): string |
| 71 |
{ |
| 72 |
return 'text/plain'; |
| 73 |
} |
| 74 |
} |