-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathExtension.php
More file actions
69 lines (55 loc) · 1.72 KB
/
Copy pathExtension.php
File metadata and controls
69 lines (55 loc) · 1.72 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace NumNum\UBL;
use function Sabre\Xml\Deserializer\keyValue;
use function Sabre\Xml\Deserializer\mixedContent;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlDeserializable;
use Sabre\Xml\XmlSerializable;
use Doctrine\Common\Collections\ArrayCollection;
class Extension implements XmlSerializable, XmlDeserializable
{
private $content;
private array $attributes = [];
public function getContent()
{
return $this->content;
}
public function setContent($content): self
{
$this->content = $content;
return $this;
}
public function getAttributes(): array
{
return $this->attributes;
}
public function setAttributes(array $attributes): self
{
$this->attributes = $attributes;
return $this;
}
public function xmlSerialize(Writer $writer): void
{
$writer->write([
[
'name' => Schema::EXT . 'UBLExtension',
'value' => [
Schema::EXT . 'ExtensionContent' => $this->content
],
'attributes' => $this->attributes
]
]);
}
public static function xmlDeserialize(Reader $reader)
{
$keyValues = keyValue($reader);
$mixedContent = mixedContent($reader);
$collection = new ArrayCollection($mixedContent);
$extensionContentTag = ReaderHelper::getTag(Schema::EXT . 'ExtensionContent', $collection);
return (new static())
->setContent($keyValues[Schema::EXT . 'ExtensionContent'] ?? null)
->setAttributes(isset($extensionContentTag, $extensionContentTag['attributes']) ? $extensionContentTag['attributes'] : [])
;
}
}