|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the thealternativezurich/feedback project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Florian Moser <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace App\Normalizer; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Serializer\Exception\CircularReferenceException; |
|
15
|
|
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
|
16
|
|
|
use Symfony\Component\Serializer\Exception\LogicException; |
|
17
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
|
18
|
|
|
|
|
19
|
|
|
class DateTimeNormalizer implements NormalizerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Normalizes an object into a set of arrays/scalars. |
|
23
|
|
|
* |
|
24
|
|
|
* @param \DateTime $object Object to normalize |
|
25
|
|
|
* @param string $format Format the normalization result will be encoded as |
|
26
|
|
|
* @param array $context Context options for the normalizer |
|
27
|
|
|
* |
|
28
|
|
|
* @throws InvalidArgumentException Occurs when the object given is not an attempted type for the normalizer |
|
29
|
|
|
* @throws CircularReferenceException Occurs when the normalizer detects a circular reference when no circular |
|
30
|
|
|
* reference handler can fix it |
|
31
|
|
|
* @throws LogicException Occurs when the normalizer is not called in an expected context |
|
32
|
|
|
* |
|
33
|
|
|
* @return array|string|int|float|bool |
|
34
|
|
|
*/ |
|
35
|
|
|
public function normalize($object, $format = null, array $context = []) |
|
36
|
|
|
{ |
|
37
|
|
|
return $object->format('c'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Checks whether the given class is supported for normalization by this normalizer. |
|
42
|
|
|
* |
|
43
|
|
|
* @param mixed $data Data to normalize |
|
44
|
|
|
* @param string $format The format being (de-)serialized from or into |
|
45
|
|
|
* |
|
46
|
|
|
* @return bool |
|
47
|
|
|
*/ |
|
48
|
|
|
public function supportsNormalization($data, $format = null) |
|
49
|
|
|
{ |
|
50
|
|
|
return $data instanceof \DateTime; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|