@@ -196,7 +196,11 @@ public static function __callStatic($name, $arguments)
196
196
$ attrName = $ attrValue ;
197
197
}
198
198
199
- $ elem ->setAttribute ($ attrName , $ attrValue );
199
+ if (self ::isVisible ($ elem ->tagName , $ attrName , $ attrValue ) ||
200
+ $ attrValue != false && $ attrValue != "false " )
201
+ {
202
+ $ elem ->setAttribute ($ attrName , $ attrValue );
203
+ }
200
204
}
201
205
}
202
206
@@ -208,7 +212,7 @@ public static function __callStatic($name, $arguments)
208
212
if (isset ($ arguments [1 ]) && is_callable ($ arguments [1 ]))
209
213
{
210
214
self ::$ parentNodes [] = $ elem ;
211
- $ retVal = $ arguments [1 ]();
215
+ $ retVal = $ arguments [1 ]($ elem );
212
216
213
217
if ($ retVal instanceof \Traversable)
214
218
{
@@ -231,6 +235,21 @@ public static function __callStatic($name, $arguments)
231
235
return $ elem ->ownerDocument ->saveHTML ($ elem );
232
236
}
233
237
238
+ private static function isVisible ($ elem , $ attrName , $ attrValue )
239
+ {
240
+ $ html = new \DOMDocument ();
241
+
242
+ $ elem = $ html ->createElement ($ elem );
243
+ $ elem ->setAttribute ($ attrName , $ attrValue );
244
+ $ html ->appendChild ($ elem );
245
+
246
+ if ($ attrValue && strpos ($ html ->saveHTML (), $ attrValue ) !== false ) {
247
+ return true ;
248
+ }
249
+
250
+ return false ;
251
+ }
252
+
234
253
/**
235
254
* @param string $tag
236
255
* @param array &$attrs
@@ -721,4 +740,4 @@ public function __toString()
721
740
{
722
741
return self ::$ document ->saveHTML ();
723
742
}
724
- }
743
+ }
0 commit comments