1 | <?php |
||
12 | final class PlainMessageNormalizer implements NormalizerInterface, DenormalizerInterface |
||
13 | { |
||
14 | /** |
||
15 | * {@inheritdoc} |
||
16 | */ |
||
17 | 1 | public function normalize($object, $format = null, array $context = []) |
|
18 | { |
||
19 | return [ |
||
20 | 1 | 'name' => $object->getName(), |
|
21 | 1 | 'arguments' => $object->all(), |
|
22 | 1 | ]; |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | 1 | public function denormalize($data, $class, $format = null, array $context = []) |
|
29 | { |
||
30 | try { |
||
31 | 1 | Assertion::notEmptyKey($data, 'name'); |
|
32 | 1 | Assertion::keyExists($data, 'arguments'); |
|
33 | 1 | Assertion::isArray($data['arguments']); |
|
34 | 1 | } catch (AssertionFailedException $e) { |
|
35 | throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e); |
||
36 | } |
||
37 | |||
38 | 1 | return new PlainMessage($data['name'], $data['arguments']); |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function supportsDenormalization($data, $type, $format = null) |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function supportsNormalization($data, $format = null) |
||
56 | } |
||
57 |