@@ -55,19 +55,16 @@ class DomNode extends DomNodeIterable
55
55
/**
56
56
* Creates a node.
57
57
*
58
- * Example 1 :
58
+ * Examples :
59
59
* ```php
60
60
* // creates a simple node with two attributes and inner text
61
61
* $item = new DomNode("item", array("id" => 101, "title" => "Title 101"), "Inner text here...");
62
62
* echo $item;
63
- * ```
64
63
*
65
- * Example 2:
66
- * ```php
67
64
* // creates a complex node
68
65
* // in this case we use a callback function to add complex structures into the node
69
66
* $root = new DomNode("root", function ($target) {
70
- * // adds three subnodes
67
+ * // adds three subnodes
71
68
* for ($i = 0; $i < 3; $i++) {
72
69
* $target->append(
73
70
* new DomNode("item", array("id" => $i, "title" => "Title $i"), "This is the item $i")
@@ -82,29 +79,21 @@ class DomNode extends DomNodeIterable
82
79
* });
83
80
* echo $root;
84
81
* ```
85
- * Example 3:
86
- * ```php
87
- * // if not specified, DomNode creates a default DOMDocument instance. But you can pass to the
88
- * // constructor a given document.
89
- * $doc = new DOMDocument("1.0", "utf-8");
90
- * $root = new DomNode($doc, "root", "Inner text...");
91
- * echo $doc->saveXML();
92
- * ```
93
82
*
94
- * @param DOMDocument $document DOM Document (not required)
95
- * @param string $nodeName Node name (not required)
96
- * @param array $attributes List of attributes (not required)
97
- * @param string $text Inner text (not required)
98
- * @param string $callback Callback function (not required)
83
+ * @param string $nodeName Node name (not required)
84
+ * @param string $document Document context (not required)
85
+ * @param array $attributes List of attributes (not required)
86
+ * @param string $text Inner text (not required)
87
+ * @param string $callback Callback function (not required)
99
88
*/
100
89
public function __construct (
101
- $ document = null , $ nodeName = null , $ attributes = null , $ text = null , $ callback = null
90
+ $ nodeName = null , $ document = null , $ attributes = null , $ text = null , $ callback = null
102
91
) {
103
92
$ args = ArrHelper::fetch (
104
93
func_get_args (),
105
94
array (
106
- "document " => "\DOMDocument " ,
107
95
"nodeName " => "string " ,
96
+ "document " => "\DOMDocument " ,
108
97
"attributes " => "array " ,
109
98
"text " => "scalar " ,
110
99
"callback " => "function "
@@ -146,27 +135,24 @@ public function __construct(
146
135
/**
147
136
* Creates an instance from a given string.
148
137
*
149
- * @param string $str Well formed document
150
- * @param string $contentType Content Type (default is "text/xml")
151
- * @param DOMDocument $document DOM Document (not required)
138
+ * @param string $str Well formed document
139
+ * @param string $contentType Content Type (default is "text/xml")
152
140
*
153
141
* @return DomNode
154
142
*/
155
- public static function createFromString ($ str , $ contentType = "text/xml " , $ document = null )
143
+ public static function createFromString ($ str , $ contentType = "text/xml " )
156
144
{
157
- if ($ document == null ) {
158
- $ document = new DOMDocument ("1.0 " );
159
- $ document ->preserveWhiteSpace = false ;
160
- $ document ->formatOutput = true ;
161
- }
145
+ $ doc = new DOMDocument ("1.0 " );
146
+ $ doc ->preserveWhiteSpace = false ;
147
+ $ doc ->formatOutput = true ;
162
148
163
149
// use internal errors
164
150
$ useInternalErrors = libxml_use_internal_errors (true );
165
151
166
152
if ($ contentType == "text/html " ) {
167
- $ document ->loadHTML ($ str );
153
+ $ doc ->loadHTML ($ str );
168
154
} else {
169
- $ document ->loadXML ($ str );
155
+ $ doc ->loadXML ($ str );
170
156
}
171
157
172
158
// retrieves the errors
@@ -188,8 +174,8 @@ public static function createFromString($str, $contentType = "text/xml", $docume
188
174
}
189
175
190
176
$ node = new static ();
191
- $ node ->document = $ document ;
192
- $ node ->elements = array ($ document ->documentElement );
177
+ $ node ->document = $ doc ;
178
+ $ node ->elements = array ($ doc ->documentElement );
193
179
194
180
return $ node ;
195
181
}
0 commit comments