Skip to content

Commit

Permalink
Merge pull request #9 from sunrise-php/release/v2.3.0
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
fenric authored Nov 19, 2021
2 parents 25ecd51 + b15ffc8 commit b25be68
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 182 deletions.
11 changes: 10 additions & 1 deletion src/EntityHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
use function array_key_exists;
use function class_exists;
use function ctype_digit;
use function date_create;
use function date_create_immutable;
use function date_diff;
Expand Down Expand Up @@ -391,7 +392,7 @@ private function hydrateFieldWithManyAssociations(
private function resolveAssociation(string $targetEntity, $value) : ?object
{
if (is_int($value) || is_string($value)) {
return $this->entityManager->getReference($targetEntity, $value);
return $this->entityManager->getRepository($targetEntity)->find($value);
}

if (is_array($value)) {
Expand Down Expand Up @@ -571,6 +572,10 @@ private function createDateTime($value) : ?DateTime
if ($value instanceof DateTime) {
return $value;
} elseif (is_string($value)) {
if (ctype_digit($value)) {
return date_create()->setTimestamp((int) $value) ?: null;
}

return date_create($value) ?: null;
} elseif (is_int($value)) {
return date_create()->setTimestamp($value);
Expand All @@ -593,6 +598,10 @@ private function createDateTimeImmutable($value) : ?DateTimeImmutable
if ($value instanceof DateTimeImmutable) {
return $value;
} elseif (is_string($value)) {
if (ctype_digit($value)) {
return date_create_immutable()->setTimestamp((int) $value) ?: null;
}

return date_create_immutable($value) ?: null;
} elseif (is_int($value)) {
return date_create_immutable()->setTimestamp($value);
Expand Down
Loading

0 comments on commit b25be68

Please sign in to comment.