Merge pull request 'FIX: casos en que PDO::execute retorna falso, pero sin tirar PDOException' (#20) from hotfix/cleaunp into develop
Reviewed-on: #20
This commit is contained in:
@ -26,7 +26,13 @@ abstract class Model implements Define\Model
|
|||||||
public function jsonSerialize(): mixed
|
public function jsonSerialize(): mixed
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id
|
'id' => $this->id,
|
||||||
|
...$this->jsonComplement()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function jsonComplement(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,9 +204,11 @@ abstract class Repository implements Define\Repository
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
$result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||||
|
if ($result === false) {
|
||||||
|
throw new EmptyResult($query);
|
||||||
|
}
|
||||||
} catch (PDOException $exception) {
|
} catch (PDOException $exception) {
|
||||||
throw new EmptyResult($query, $exception);
|
throw new EmptyResult($query, $exception);
|
||||||
|
|
||||||
}
|
}
|
||||||
return $this->load($result);
|
return $this->load($result);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Common\Implement\Repository\Mapper;
|
namespace Incoviba\Common\Implement\Repository\Mapper;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use DateMalformedStringException;
|
||||||
use Incoviba\Common\Implement\Repository\Mapper;
|
use Incoviba\Common\Implement\Repository\Mapper;
|
||||||
|
|
||||||
class DateTime extends Mapper
|
class DateTime extends Mapper
|
||||||
@ -9,7 +10,17 @@ class DateTime extends Mapper
|
|||||||
public function __construct(string $column, ?string $property = null)
|
public function __construct(string $column, ?string $property = null)
|
||||||
{
|
{
|
||||||
$this->setFunction(function($data) use ($column) {
|
$this->setFunction(function($data) use ($column) {
|
||||||
|
if (!isset($data[$column])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (is_a($data[$column], DateTimeImmutable::class)) {
|
||||||
|
return $data[$column];
|
||||||
|
}
|
||||||
|
try {
|
||||||
return new DateTimeImmutable($data[$column] ?? '');
|
return new DateTimeImmutable($data[$column] ?? '');
|
||||||
|
} catch (DateMalformedStringException) {
|
||||||
|
return new DateTimeImmutable();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if ($property !== null) {
|
if ($property !== null) {
|
||||||
$this->setProperty($property);
|
$this->setProperty($property);
|
||||||
|
Reference in New Issue
Block a user