4 Commits
2.2.3 ... 2.2.5

Author SHA1 Message Date
4ccc38ffac Merge branch 'develop' into release 2022-09-12 17:39:15 -03:00
ef1603bc4b FIX: Check for missing getters and setters 2022-09-12 17:39:00 -03:00
8531658899 FIX 2022-09-12 17:34:05 -03:00
f19385ccc1 FIX: use getMethod instead of string 2022-09-12 17:33:45 -03:00

View File

@ -150,25 +150,35 @@ abstract class Repository implements RepositoryInterface
public function fillData(Model $model, array $data): Model public function fillData(Model $model, array $data): Model
{ {
foreach ($this->getRequired() as $column) { foreach ($this->getRequired() as $column) {
$m = 'set' . ucwords($column); $m = $this->getMethod($column, false);
if (!method_exists($model, $m)) {
continue;
}
$model->{$m}($data[$column]); $model->{$m}($data[$column]);
} }
foreach ($this->getOptional() as $column) { foreach ($this->getOptional() as $column) {
if (isset($data[$column])) { if (!isset($data[$column])) {
$m = 'set' . ucwords($column); continue;
$model->{$m}($data[$column]);
} }
$m = $this->getMethod($column, false);
if (!method_exists($model, $m)) {
continue;
}
$model->{$m}($data[$column]);
} }
return $model; return $model;
} }
public function mapArray(Model $model, array $data): array public function mapArray(Model $model, array $data): array
{ {
foreach ($this->getColumns() as $column) { foreach ($this->getColumns() as $column) {
$m = $this->getMethod($column);
$val = $model->{$m}();
if (isset($data[$column])) { if (isset($data[$column])) {
continue; continue;
} }
$m = $this->getMethod($column);
if (!method_exists($model, $m)) {
continue;
}
$val = $model->{$m}();
$data[$column] = $val; $data[$column] = $val;
} }
return $data; return $data;
@ -215,7 +225,10 @@ abstract class Repository implements RepositoryInterface
{ {
foreach ($this->getColumns() as $col) { foreach ($this->getColumns() as $col) {
if (isset($data[$col])) { if (isset($data[$col])) {
$m = 'set' . ucwords($col); $m = $this->getMethod($col, false);
if (!method_exists($model, $m)) {
continue;
}
$model->{$m}($data[$col]); $model->{$m}($data[$col]);
} }
} }