From 8696f51ae5a676f59d941a28d35e17760e20d09f Mon Sep 17 00:00:00 2001 From: Manuel Reinhard Date: Thu, 18 Jun 2020 17:48:53 +0200 Subject: [PATCH] Use writerOptions instead of class property to force xlink:href --- pr.txt | 0 src/QrCode.php | 13 ------------- src/QrCodeInterface.php | 2 -- src/Writer/SvgWriter.php | 12 ++++++++++-- 4 files changed, 10 insertions(+), 17 deletions(-) create mode 100644 pr.txt diff --git a/pr.txt b/pr.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/QrCode.php b/src/QrCode.php index 43aa23e..088c0a5 100644 --- a/src/QrCode.php +++ b/src/QrCode.php @@ -61,9 +61,6 @@ class QrCode implements QrCodeInterface /** @var int|null */ private $logoHeight; - /** @var bool */ - private $logoForceXlinkHref = false; - /** @var string */ private $label; @@ -237,16 +234,6 @@ public function getLogoHeight(): ?int return $this->logoHeight; } - public function setLogoForceXlinkHref(bool $logoForceXlinkHref): void - { - $this->logoForceXlinkHref = $logoForceXlinkHref; - } - - public function getLogoForceXlinkHref(): bool - { - return $this->logoForceXlinkHref; - } - public function setLabel(string $label, int $labelFontSize = null, string $labelFontPath = null, string $labelAlignment = null, array $labelMargin = null): void { $this->label = $label; diff --git a/src/QrCodeInterface.php b/src/QrCodeInterface.php index ecd67e7..e6382a7 100644 --- a/src/QrCodeInterface.php +++ b/src/QrCodeInterface.php @@ -35,8 +35,6 @@ public function getLogoWidth(): ?int; public function getLogoHeight(): ?int; - public function getLogoForceXlinkHref(): bool; - public function getLabel(): ?string; public function getLabelFontPath(): string; diff --git a/src/Writer/SvgWriter.php b/src/Writer/SvgWriter.php index cf94581..40970e6 100644 --- a/src/Writer/SvgWriter.php +++ b/src/Writer/SvgWriter.php @@ -21,6 +21,8 @@ class SvgWriter extends AbstractWriter { public function writeString(QrCodeInterface $qrCode): string { + $options = $qrCode->getWriterOptions(); + if ($qrCode->getValidateResult()) { throw new ValidationException('Built-in validation reader can not check SVG images: please disable via setValidateResult(false)'); } @@ -64,7 +66,13 @@ public function writeString(QrCodeInterface $qrCode): string $logoPath = $qrCode->getLogoPath(); if (is_string($logoPath)) { - $this->addLogo($svg, $data['outer_width'], $data['outer_height'], $logoPath, $qrCode->getLogoWidth(), $qrCode->getLogoHeight(), $qrCode->getLogoForceXlinkHref()); + + $forceXlinkHref = false; + if (isset($options['force_xlink_href']) && $options['force_xlink_href']) { + $forceXlinkHref = true; + } + + $this->addLogo($svg, $data['outer_width'], $data['outer_height'], $logoPath, $qrCode->getLogoWidth(), $qrCode->getLogoHeight(), $forceXlinkHref); } $xml = $svg->asXML(); @@ -73,7 +81,7 @@ public function writeString(QrCodeInterface $qrCode): string throw new GenerateImageException('Unable to save SVG XML'); } - $options = $qrCode->getWriterOptions(); + if (isset($options['exclude_xml_declaration']) && $options['exclude_xml_declaration']) { $xml = str_replace("\n", '', $xml); }