| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Endroid\QrCode\Writer\Result; |
| 6 |
|
| 7 |
use Endroid\QrCode\Matrix\MatrixInterface; |
| 8 |
|
| 9 |
final class SvgResult extends AbstractResult |
| 10 |
{ |
| 11 |
public function __construct( |
| 12 |
MatrixInterface $matrix, |
| 13 |
private readonly \SimpleXMLElement $xml, |
| 14 |
private readonly bool $excludeXmlDeclaration = false |
| 15 |
) { |
| 16 |
parent::__construct($matrix); |
| 17 |
} |
| 18 |
|
| 19 |
public function getXml(): \SimpleXMLElement |
| 20 |
{ |
| 21 |
return $this->xml; |
| 22 |
} |
| 23 |
|
| 24 |
public function getString(): string |
| 25 |
{ |
| 26 |
$string = $this->xml->asXML(); |
| 27 |
|
| 28 |
if (!is_string($string)) { |
| 29 |
throw new \Exception('Could not save SVG XML to string'); |
| 30 |
} |
| 31 |
|
| 32 |
if ($this->excludeXmlDeclaration) { |
| 33 |
$string = str_replace("<?xml version=\"1.0\"?>\n", '', $string); |
| 34 |
} |
| 35 |
|
| 36 |
return $string; |
| 37 |
} |
| 38 |
|
| 39 |
public function getMimeType(): string |
| 40 |
{ |
| 41 |
return 'image/svg+xml'; |
| 42 |
} |
| 43 |
} |