@@ -137,5 +137,78 @@ public static function generContentNode($content = '')
137
137
return (new self ('content ' ))->setNodeId ()->setContent ($ content );
138
138
}
139
139
140
+ /**
141
+ * @return string
142
+ */
143
+ public function __toString ()
144
+ {
145
+ # config
146
+ $ config = Config::getInstance ();
147
+ $ tagIndent = $ config ->get ('tag_indent ' );
148
+ $ hideGenid = $ config ->get ('hide_genid ' );
149
+ $ tagIndentString = str_repeat ($ tagIndent , $ this ->level );
150
+
151
+ # content
152
+ if (in_array ($ this ->nodeName , ['content ' ])) {
153
+ return $ tagIndentString . $ this ->content . PHP_EOL ;
154
+ }
155
+ # root
156
+ if (in_array ($ this ->nodeName , ['root ' ])) {
157
+ return $ this ->_invParseChilds ($ this ->childs );
158
+ }
159
+ if (empty ($ this ->nodeName ))
160
+ return '' ;
161
+
162
+ # normal
163
+ $ string = $ tagIndentString . '< ' . $ this ->nodeName . ' ' ;
164
+ # id
165
+ if (!empty ($ this ->domId ))
166
+ $ string .= ' id=" ' . $ this ->domId . '" ' ;
167
+ # gener id
168
+ if ($ hideGenid == false )
169
+ $ string .= ' data-genid=" ' . $ this ->nodeId . '" ' ;
170
+ # class
171
+ if (!empty ($ this ->domAttrs ['class ' ])) {
172
+ $ string .= ' class=" ' . implode (' ' , $ this ->domAttrs ['class ' ]) . '" ' ;
173
+ unset($ this ->domAttrs ['class ' ]);
174
+ }
175
+ # style
176
+ if (!empty ($ this ->domAttrs ['style ' ])) {
177
+ // $string .= implode(' ', $this->domAttrs['class']);
178
+ unset($ this ->domAttrs ['style ' ]);
179
+ }
180
+ # attrs
181
+ if (!empty ($ this ->domAttrs )) {
182
+ foreach ($ this ->domAttrs as $ k => $ v ) {
183
+ $ string .= ' ' . $ k . '=" ' . $ v . '" ' ;
184
+ }
185
+ }
186
+ # is single
187
+ if ($ this ->isSingle == true )
188
+ return $ string . ' /> ' . PHP_EOL ;
189
+
190
+ # start tag end
191
+ $ string .= ' > ' . PHP_EOL ;
192
+
193
+ if (!empty ($ this ->childs ))
194
+ $ string .= $ this ->_invParseChilds ($ this ->childs );
195
+
196
+ # end
197
+ $ string .= $ tagIndentString . '</ ' . $ this ->nodeName . '> ' . PHP_EOL ;
198
+
199
+ return $ string ;
200
+ }
201
+
202
+ private function _invParseChilds ($ childs )
203
+ {
204
+ if (empty ($ childs ))
205
+ return '' ;
206
+
207
+ $ string = '' ;
208
+ foreach ($ childs as $ child ) {
209
+ $ string .= (string ) $ child ;
210
+ }
211
+ return $ string ;
212
+ }
140
213
141
214
}
0 commit comments