diff --git a/src/Normalizer/CarbonDenormalizer.php b/src/Normalizer/CarbonDenormalizer.php new file mode 100644 index 0000000..f7a280c --- /dev/null +++ b/src/Normalizer/CarbonDenormalizer.php @@ -0,0 +1,26 @@ +toRfc3339String(); - } - - /** - * @inheritdoc - */ - public function supportsNormalization($data, string $format = null) - { - return $data instanceof CarbonInterface; - } - - /** - * @inheritDoc - */ - public function denormalize($data, string $type, string $format = null, array $context = []) - { - return new Carbon($data); - } - - /** - * @inheritDoc - */ - public function supportsDenormalization($data, string $type, string $format = null) - { - return is_a($type, CarbonInterface::class, true); - } -} diff --git a/src/PopoFactory.php b/src/PopoFactory.php index 64384be..4c3a654 100644 --- a/src/PopoFactory.php +++ b/src/PopoFactory.php @@ -2,7 +2,7 @@ namespace Morrislaptop\PopoFactory; -use Morrislaptop\PopoFactory\Normalizer\CarbonNormalizer; +use Morrislaptop\PopoFactory\Normalizer\CarbonDenormalizer; use ReflectionClass; use ReflectionProperty; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; @@ -41,7 +41,7 @@ public function __construct(string $dataTransferObjectClass, Serializer $seriali { $this->dataTransferObjectClass = $dataTransferObjectClass; $this->serializer = $serializer ?: new Serializer([ - new CarbonNormalizer, + new CarbonDenormalizer, new DateTimeNormalizer, new ArrayDenormalizer, new ObjectNormalizer,