1 | <?php |
||
14 | final class TimestampNormalizer implements DenormalizerInterface, NormalizerInterface |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | 1 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
20 | { |
||
21 | 1 | return new \DateTime($data); |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | 50 | public function supportsDenormalization($data, $type, $format = null) |
|
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 1 | public function normalize($object, $format = null, array $context = array()) |
|
36 | { |
||
37 | 1 | if (!($object instanceof \DateTime || $object instanceof \DateTimeInterface)) { |
|
38 | throw new InvalidArgumentException(sprintf('Expected \DateTime object or object implementing \DateTimeInterface (got "%s").', is_object($object) ? get_class($object) : gettype($object))); |
||
39 | } |
||
40 | |||
41 | 1 | return $object->format('c'); |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 49 | public function supportsNormalization($data, $format = null) |
|
51 | } |
||
52 |