Skip to content

Commit

Permalink
Use writerOptions instead of class property to force xlink:href
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Jun 18, 2020
1 parent 530e6cc commit 8696f51
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
Empty file added pr.txt
Empty file.
13 changes: 0 additions & 13 deletions src/QrCode.php
Expand Up @@ -61,9 +61,6 @@ class QrCode implements QrCodeInterface
/** @var int|null */
private $logoHeight;

/** @var bool */
private $logoForceXlinkHref = false;

/** @var string */
private $label;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/QrCodeInterface.php
Expand Up @@ -35,8 +35,6 @@ public function getLogoWidth(): ?int;

public function getLogoHeight(): ?int;

public function getLogoForceXlinkHref(): bool;

public function getLabel(): ?string;

public function getLabelFontPath(): string;
Expand Down
12 changes: 10 additions & 2 deletions src/Writer/SvgWriter.php
Expand Up @@ -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)');
}
Expand Down Expand Up @@ -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();
Expand All @@ -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("<?xml version=\"1.0\"?>\n", '', $xml);
}
Expand Down

0 comments on commit 8696f51

Please sign in to comment.