Skip to content

Commit

Permalink
Merge pull request #128 from analogueorm/feature/entity-fill-method
Browse files Browse the repository at this point in the history
Add fill() method to base Entity class
  • Loading branch information
RemiCollin authored Aug 17, 2016
2 parents 5947bea + 378703a commit 45ee708
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,24 @@ public function toArray()
}
return $attributes;
}

/**
* Fill an entity with key-value pairs
*
* @param array $attributes
* @return void
*/
public function fill(array $attributes)
{
foreach ($attributes as $key => $attribute) {

if ($this->hasSetMutator($key)) {
$method = 'set' . $this->getMutatorMethod($key);
$this->attributes[$key] = $this->$method($attribute);
}
else {
$this->attributes[$key] = $attribute;
}
}
}
}

0 comments on commit 45ee708

Please sign in to comment.