|
1
|
|
|
<?php |
|
2
|
|
|
namespace nstdio\svg\xml; |
|
3
|
|
|
|
|
4
|
|
|
use DOMDocument; |
|
5
|
|
|
use nstdio\svg\Base; |
|
6
|
|
|
use nstdio\svg\traits\ElementTrait; |
|
7
|
|
|
use nstdio\svg\XMLDocumentInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class DomWrapper |
|
11
|
|
|
* |
|
12
|
|
|
* @package nstdio\svg\xml |
|
13
|
|
|
* @author Edgar Asatryan <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
final class DOMWrapper implements XMLDocumentInterface |
|
16
|
|
|
{ |
|
17
|
|
|
use ElementTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var DOMDocument |
|
21
|
|
|
*/ |
|
22
|
|
|
private $dom; |
|
23
|
|
|
|
|
24
|
119 |
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
119 |
|
$this->dom = new DOMDocument(Base::DOM_VERSION, Base::DOM_ENCODING); |
|
27
|
119 |
|
$this->dom->xmlStandalone = false; |
|
28
|
119 |
|
$this->dom->formatOutput = true; |
|
29
|
119 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function setAttribute($name, $value = null) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->dom->documentElement->setAttribute($name, $value); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getAttribute($name) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->dom->documentElement->getAttribute($name); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function setAttributeNS($namespaceURI, $qualifiedName, $value) |
|
42
|
|
|
{ |
|
43
|
|
|
// TODO: Implement setAttributeNS() method. |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getAttributeNS($namespaceURI, $localName) |
|
47
|
|
|
{ |
|
48
|
|
|
// TODO: Implement getAttributeNS() method. |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
119 |
|
public function appendChild(XMLDocumentInterface $newNode) |
|
52
|
|
|
{ |
|
53
|
119 |
|
return $this->dom->appendChild($newNode->getElement()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
119 |
|
public function createElement($name, $value = null) |
|
57
|
|
|
{ |
|
58
|
|
|
// on PHP 5.4.* createElement method with null parameter will create empty DOMText object as child of created element |
|
59
|
119 |
|
$element = $value === null ? $this->dom->createElement($name) : $this->dom->createElement($name, $value); |
|
60
|
|
|
|
|
61
|
119 |
|
return new DOMElementWrapper($element); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function createElementNS($namespaceURI, $qualifiedName, $value = null) |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->dom->createElementNS($namespaceURI, $qualifiedName, $value); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
119 |
|
public static function isLoaded() |
|
70
|
|
|
{ |
|
71
|
119 |
|
return extension_loaded('dom'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
42 |
|
public function saveHTML() |
|
75
|
|
|
{ |
|
76
|
42 |
|
return $this->dom->saveHTML(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getElement() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->dom->documentElement; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param $value |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setNodeValue($value) |
|
88
|
|
|
{ |
|
89
|
|
|
throw NotImplementedException::newInstance(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function getNodeValue() |
|
93
|
|
|
{ |
|
94
|
|
|
throw NotImplementedException::newInstance(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritdoc |
|
99
|
|
|
*/ |
|
100
|
|
|
public function removeNode(XMLDocumentInterface $child) |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->dom->documentElement->removeChild($child->getElement()); |
|
103
|
|
|
} |
|
104
|
|
|
} |