-
-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy pathSvgResult.php
More file actions
45 lines (35 loc) · 970 Bytes
/
SvgResult.php
File metadata and controls
45 lines (35 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace Endroid\QrCode\Writer\Result;
use Endroid\QrCode\Matrix\MatrixInterface;
final class SvgResult extends AbstractResult
{
public function __construct(
MatrixInterface $matrix,
private readonly \SimpleXMLElement $xml,
private readonly bool $excludeXmlDeclaration = false,
) {
parent::__construct($matrix);
}
public function getXml(): \SimpleXMLElement
{
return $this->xml;
}
#[\Override]
public function getString(): string
{
$string = $this->xml->asXML();
if (!is_string($string)) {
throw new \Exception('Could not save SVG XML to string');
}
if ($this->excludeXmlDeclaration) {
$string = str_replace("<?xml version=\"1.0\"?>\n", '', $string);
}
return $string;
}
#[\Override]
public function getMimeType(): string
{
return 'image/svg+xml';
}
}