public function attr($attribute, ...$arguments)
{
if (count($arguments) == 0 && is_string($attribute)) {
//empty value - read attribute from first element in list
$attribute = (new QualifiedName($attribute))->name;
$node = $this->getFirstElement();
if ($node && $node->hasAttribute($attribute)) {
return $node->getAttribute($attribute);
}
return NULL;
} else {
$attributes = $this->getSetterValues($attribute, isset($arguments[0]) ? $arguments[0] : NULL);
// set attributes on each element
foreach ($attributes as $key => $value) {
$name = (new QualifiedName($key))->name;
$callback = Constraints::isCallable($value);
$this->each(function (\DOMElement $node, $index) use($name, $value, $callback) {
$node->setAttribute($name, $callback ? (string) $callback($node, $index, $node->getAttribute($name)) : (string) $value);
}, TRUE);
}
}
return $this;
}