Skip to content

Commit

Permalink
Gestion des null values pour setter des dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume DUBOST committed Mar 4, 2020
1 parent 31f6995 commit 16222ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Entity/AbstractEntityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ protected function setPropertiesToEntity(array $datas, array $validation_groups,
case 1 === preg_match(
"#^(date|datetime|time)[a-z_]*$#",
$doctrine_field_metadata[$field_name]["type"]
):
if (is_string($data_value)) {
$filtered_datas[$field_name] = new \DateTime($data_value);
}
) && is_string($data_value):
$filtered_datas[$field_name] = new \DateTime($data_value);
break;
// Sinon on sette tel quel
default:
Expand Down
3 changes: 3 additions & 0 deletions src/Extensions/GetSetDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ protected function setDateField($field_name, $date)
case is_object($date) && 'DateTime' !== get_class($date):
case is_string($date) && !preg_match("#^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$#", trim($date)):
throw new \Exception("bad {$field_name} provided", 400);
case null === $date:
$this->{$field_name} = null;
break;
default:
$this->{$field_name} = $date instanceof \DateTime ? $date : new \DateTime($date);
}
Expand Down

0 comments on commit 16222ba

Please sign in to comment.