Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #45
This commit is contained in:
2025-10-04 11:40:52 -03:00
parent 6ddc48ec60
commit 742de657c5
815 changed files with 62089 additions and 3287 deletions

View File

@ -1,8 +1,10 @@
<?php
namespace Incoviba\Common\Implement\Repository;
use Error;
use Closure;
use Incoviba\Common\Define;
use Incoviba\Common\Implement\Exception\EmptyResult;
class Mapper implements Define\Repository\Mapper
{
@ -46,7 +48,11 @@ class Mapper implements Define\Repository\Mapper
}
public function hasDefault(): bool
{
return isset($this->default);
try {
return isset($this->default) or $this->default === null;
} catch (Error) {
return false;
}
}
public function parse(Define\Model &$model, string $column, ?array $data): bool
@ -62,10 +68,14 @@ class Mapper implements Define\Repository\Mapper
}
$value = $data[$column];
if ($this->hasFunction()) {
if ($value !== null) {
try {
$value = ($this->function)($data);
} elseif ($this->hasDefault()) {
$value = $this->default;
} catch (EmptyResult $exception) {
if ($this->hasDefault()) {
$value = $this->default;
} else {
throw $exception;
}
}
}
$model->{$property} = $value;