Skip to content

Commit

Permalink
Improved add attribute feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Edujugon committed Apr 23, 2018
1 parent f47e051 commit c3d3158
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/XMLMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,27 +459,28 @@ public function wrapWith($tagName)
*
* @param $tagName
* @param array $attributes
* @return $this
*/
public function addAttributes(array $attributes, $tagName = null)
{
$obj = $this->getObj();

if (is_null($tagName) || $tagName === $obj->getName()) {
$this->addAttributesToObj($obj, $attributes);
} else {
foreach ($obj->children() as $key => $element) {
if ($key === $tagName) {
$this->addAttributesToObj($element, $attributes);

return;
}

foreach ($obj->children() as $key => $element) {
if ($key === $tagName) {
$this->addAttributesToObj($element, $attributes);

return;
break;
}
}
}

//update xml
$this->loadObj($obj);

return $this;
}

/**
Expand Down

0 comments on commit c3d3158

Please sign in to comment.