public function assign($values, array $whitelist = null)
{
if ($whitelist !== null) {
$whitelist = array_flip($whitelist);
}
if (!is_array($values) and !$values instanceof Traversable) {
$givenType = gettype($values) !== 'object' ? gettype($values) : 'instance of ' . get_class($values);
throw new InvalidArgumentException("Argument \$values in " . get_called_class() . "::assign must contain either array or instance of Traversable, {$givenType} given.");
}
foreach ($values as $property => $value) {
if ($whitelist === null or isset($whitelist[$property])) {
$this->__set($property, $value);
}
}
}