for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Xabbuh\XApi\Serializer\Normalizer;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Normalizes and denormalizes xAPI statement timestamps.
*
* @author Christian Flothmann <[email protected]>
*/
final class TimestampNormalizer implements DenormalizerInterface, NormalizerInterface
{
* {@inheritdoc}
public function denormalize($data, $class, $format = null, array $context = array())
return new \DateTime($data);
}
public function supportsDenormalization($data, $type, $format = null)
return '\DateTime' === $type;
public function normalize($object, $format = null, array $context = array())
if (!($object instanceof \DateTime || $object instanceof \DateTimeInterface)) {
throw new InvalidArgumentException(sprintf('Expected \DateTime object or object implementing \DateTimeInterface (got "%s").', is_object($object) ? get_class($object) : gettype($object)));
return $object->format('c');
public function supportsNormalization($data, $format = null)
return $data instanceof \DateTime || $data instanceof \DateTimeInterface;