1
|
|
|
<?php |
2
|
|
|
namespace nstdio\svg\xml; |
3
|
|
|
|
4
|
|
|
use nstdio\svg\util\KeyValueWriter; |
5
|
|
|
use nstdio\svg\XMLDocumentInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class DOMNode |
9
|
|
|
* |
10
|
|
|
* @package nstdio\svg\xml |
11
|
|
|
* @author Edgar Asatryan <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
abstract class DOMNode implements XMLDocumentInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @inheritdoc |
17
|
|
|
*/ |
18
|
|
|
abstract public function setNodeValue($value); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @inheritdoc |
22
|
|
|
*/ |
23
|
|
|
abstract public function getNodeValue(); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
8 |
|
public function attributes(array $except = []) |
29
|
|
|
{ |
30
|
8 |
|
return KeyValueWriter::allAttributes($this->getElement(), $except); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
abstract public function getElement(); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
*/ |
41
|
149 |
|
public function setAttribute($name, $value = null) |
42
|
|
|
{ |
43
|
149 |
|
$this->getElement()->setAttribute($name, $value); |
|
|
|
|
44
|
149 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
109 |
|
public function getAttribute($name) |
50
|
|
|
{ |
51
|
109 |
|
return $this->getElement()->getAttribute($name); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
149 |
|
public function setAttributeNS($namespaceURI, $qualifiedName, $value) |
58
|
|
|
{ |
59
|
149 |
|
$this->getElement()->setAttributeNS($namespaceURI, $qualifiedName, $value); |
|
|
|
|
60
|
149 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritdoc |
64
|
|
|
*/ |
65
|
81 |
|
public function getAttributeNS($namespaceURI, $localName) |
66
|
|
|
{ |
67
|
81 |
|
return $this->getElement()->getAttributeNS($namespaceURI, $localName); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
149 |
|
public function appendChild(XMLDocumentInterface $newNode) |
71
|
|
|
{ |
72
|
149 |
|
$this->getElement()->appendChild($newNode->getElement()); |
|
|
|
|
73
|
149 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritdoc |
77
|
|
|
*/ |
78
|
149 |
|
public function createElement($name, $value = null) |
79
|
|
|
{ |
80
|
|
|
// on PHP 5.4.* createElement method with null parameter will create empty DOMText object as child of created element |
81
|
149 |
|
$element = $value === null ? $this->getElement()->createElement($name) : $this->getElement()->createElement($name, $value); |
|
|
|
|
82
|
|
|
|
83
|
149 |
|
return new DOMElementWrapper($element); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdoc |
88
|
|
|
*/ |
89
|
|
|
public function createElementNS($namespaceURI, $qualifiedName, $value = null) |
90
|
|
|
{ |
91
|
|
|
return $this->getElement()->createElementNS($namespaceURI, $qualifiedName, $value); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @inheritdoc |
96
|
|
|
*/ |
97
|
9 |
|
public function removeNode(XMLDocumentInterface $child) |
98
|
|
|
{ |
99
|
9 |
|
return $this->getElement()->removeChild($child->getElement()); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @inheritdoc |
104
|
|
|
*/ |
105
|
62 |
|
public function saveHTML() |
106
|
|
|
{ |
107
|
62 |
|
return $this->getElement()->saveHTML(); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
2 |
|
public function saveXML($formatOutput) |
111
|
|
|
{ |
112
|
2 |
|
return $this->getElement()->saveXML(); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @inheritdoc |
117
|
|
|
*/ |
118
|
149 |
|
public static function isLoaded() |
119
|
|
|
{ |
120
|
149 |
|
return extension_loaded('dom'); |
121
|
|
|
} |
122
|
|
|
|
123
|
1 |
|
public function __debugInfo() |
124
|
|
|
{ |
125
|
|
|
return [ |
126
|
1 |
|
'nodeName' => $this->getElement()->nodeName, |
127
|
1 |
|
]; |
128
|
|
|
} |
129
|
|
|
} |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.