public function setAttribute($name, $value = null)
{
if (\is_array($name)) {
$attrs = $name;
} else {
$attrs = [$name => $value];
}
foreach ($this->nodes as $n) {
foreach ($attrs as $k => $v) {
if (\is_integer($k)) {
$k = $v;
$v = null;
}
// Algorithm 1:
$n->setAttribute($k, $v);
// Algorithm 2:
// $n->setAttributeNode(new \DOMAttr($k, $v));
// Algorithm 3:
// $n->appendChild(new \DOMAttr($k, $v));
// Algorithm 2 and 3 have a different behaviour
// from Algorithm 1.
// The attribute is still created or setted, but
// changing the value of an existing attribute
// changes even the order of that attribute
// in the attribute list.
}
}
return $this;
}