Skip to content

Commit

Permalink
Add support for DateTimeInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Dec 6, 2021
1 parent 64a08ba commit 90b396a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Type/DateOutputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Nucleos\Form\Type;

use DateTime;
use DateTimeInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
Expand All @@ -31,7 +31,7 @@ public function configureOptions(OptionsResolver $resolver): void
->setDefaults([
'default' => '',
'format' => null,
'data_class' => DateTime::class,
'data_class' => DateTimeInterface::class,
'compound' => false,
'required' => false,
'disabled' => true,
Expand Down
8 changes: 4 additions & 4 deletions src/Validator/Constraints/DateAfterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Nucleos\Form\Validator\Constraints;

use DateTime;
use DateTimeInterface;
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Constraint;
Expand Down Expand Up @@ -85,7 +85,7 @@ public function validate($value, Constraint $constraint): void
/**
* @param array|object $object
*/
private function getFieldValue($object, string $field): ?DateTime
private function getFieldValue($object, string $field): ?DateTimeInterface
{
$propertyAccessor = PropertyAccess::createPropertyAccessor();

Expand All @@ -95,8 +95,8 @@ private function getFieldValue($object, string $field): ?DateTime
throw new InvalidArgumentException($e->getMessage());
}

if (null !== $value && !$value instanceof DateTime) {
throw new UnexpectedTypeException($value, DateTime::class);
if (null !== $value && !$value instanceof DateTimeInterface) {
throw new UnexpectedTypeException($value, DateTimeInterface::class);
}

return $value;
Expand Down

0 comments on commit 90b396a

Please sign in to comment.