/**
* Generate and set the model attributes.
*
* @param object $model The model instance.
* @param array $attr The model attributes.
*
* @return void
*/
protected function generate($model, array $attr = [])
{
foreach ($attr as $key => $kind) {
$value = $this->generatorFactory->generate($kind, $model, $this);
$setter = 'set' . ucfirst(self::camelize($key));
// check if there is a setter and use it instead
if (method_exists($model, $setter)) {
$model->{$setter}($value);
} else {
$model->{$key} = $value;
}
}
}