diff --git a/app/common/Ideal/Model.php b/app/common/Ideal/Model.php index eade31b..c68827a 100644 --- a/app/common/Ideal/Model.php +++ b/app/common/Ideal/Model.php @@ -26,7 +26,13 @@ abstract class Model implements Define\Model public function jsonSerialize(): mixed { return [ - 'id' => $this->id + 'id' => $this->id, + ...$this->jsonComplement() ]; } + + protected function jsonComplement(): array + { + return []; + } } diff --git a/app/common/Ideal/Repository.php b/app/common/Ideal/Repository.php index e8f9bee..9a46692 100644 --- a/app/common/Ideal/Repository.php +++ b/app/common/Ideal/Repository.php @@ -204,9 +204,11 @@ abstract class Repository implements Define\Repository { try { $result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC); + if ($result === false) { + throw new EmptyResult($query); + } } catch (PDOException $exception) { throw new EmptyResult($query, $exception); - } return $this->load($result); } diff --git a/app/common/Implement/Repository/Mapper/DateTime.php b/app/common/Implement/Repository/Mapper/DateTime.php index bbeb388..10c851d 100644 --- a/app/common/Implement/Repository/Mapper/DateTime.php +++ b/app/common/Implement/Repository/Mapper/DateTime.php @@ -2,6 +2,7 @@ namespace Incoviba\Common\Implement\Repository\Mapper; use DateTimeImmutable; +use DateMalformedStringException; use Incoviba\Common\Implement\Repository\Mapper; class DateTime extends Mapper @@ -9,7 +10,17 @@ class DateTime extends Mapper public function __construct(string $column, ?string $property = null) { $this->setFunction(function($data) use ($column) { - return new DateTimeImmutable($data[$column] ?? ''); + if (!isset($data[$column])) { + return null; + } + if (is_a($data[$column], DateTimeImmutable::class)) { + return $data[$column]; + } + try { + return new DateTimeImmutable($data[$column] ?? ''); + } catch (DateMalformedStringException) { + return new DateTimeImmutable(); + } }); if ($property !== null) { $this->setProperty($property);