| @@ 20-61 (lines=42) @@ | ||
| 17 | * |
|
| 18 | * @author John Kleijn <[email protected]> |
|
| 19 | */ |
|
| 20 | class JmsSerializerAdapter implements Serializer |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * @var JmsSerializer |
|
| 24 | */ |
|
| 25 | private $target; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * JmsSerializerAdapter constructor. |
|
| 29 | * |
|
| 30 | * @param JmsSerializer $target |
|
| 31 | */ |
|
| 32 | public function __construct(JmsSerializer $target) |
|
| 33 | { |
|
| 34 | $this->target = $target; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @param mixed $data any data |
|
| 39 | * @param Specification $specification |
|
| 40 | * |
|
| 41 | * @return string |
|
| 42 | */ |
|
| 43 | public function serialize($data, Specification $specification): string |
|
| 44 | { |
|
| 45 | return $this->target->serialize($data, 'json'); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Deserializes data into the given type. |
|
| 50 | * |
|
| 51 | * @param mixed $data |
|
| 52 | * @param string $type |
|
| 53 | * @param Specification $specification |
|
| 54 | * |
|
| 55 | * @return array|object |
|
| 56 | */ |
|
| 57 | public function deserialize($data, string $type, Specification $specification) |
|
| 58 | { |
|
| 59 | return $this->target->deserialize($data, $type, 'json'); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 20-62 (lines=43) @@ | ||
| 17 | * |
|
| 18 | * @author John Kleijn <[email protected]> |
|
| 19 | */ |
|
| 20 | class SymfonySerializerAdapter implements Serializer |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * @var SymfonySerializer |
|
| 24 | */ |
|
| 25 | private $target; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * JmsSerializerAdapter constructor. |
|
| 29 | * |
|
| 30 | * @param SymfonySerializer $target |
|
| 31 | */ |
|
| 32 | public function __construct(SymfonySerializer $target) |
|
| 33 | { |
|
| 34 | $this->target = $target; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @param mixed $data any data |
|
| 39 | * @param Specification $specification |
|
| 40 | * |
|
| 41 | * @return string |
|
| 42 | */ |
|
| 43 | public function serialize($data, Specification $specification): string |
|
| 44 | { |
|
| 45 | return $this->target->serialize($data, 'json'); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Deserializes data into the given type. |
|
| 50 | * |
|
| 51 | * @param mixed $data |
|
| 52 | * @param string $type |
|
| 53 | * |
|
| 54 | * @param Specification $specification |
|
| 55 | * |
|
| 56 | * @return array|object |
|
| 57 | */ |
|
| 58 | public function deserialize($data, string $type, Specification $specification) |
|
| 59 | { |
|
| 60 | return $this->target->deserialize($data, $type, 'json'); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||