|
4 | 4 |
|
5 | 5 | namespace WayOfDev\Serializer;
|
6 | 6 |
|
| 7 | +use ArrayObject; |
7 | 8 | use Stringable;
|
8 | 9 | use WayOfDev\Serializer\Contracts\SerializerInterface;
|
9 | 10 |
|
@@ -33,8 +34,57 @@ public function unserialize(
|
33 | 34 | return $this->getSerializer($format ?? $this->defaultFormat)->unserialize($payload, $type);
|
34 | 35 | }
|
35 | 36 |
|
36 |
| - public function normalize(mixed $data, string $format = null, array $context = []) |
| 37 | + public function normalize(mixed $data, string $format = null, array $context = []): array | string | int | float | bool | ArrayObject | null |
37 | 38 | {
|
38 | 39 | return $this->getSerializer($format ?? $this->defaultFormat)->normalize($data, $format, $context);
|
39 | 40 | }
|
| 41 | + |
| 42 | + public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed |
| 43 | + { |
| 44 | + $format ??= $this->defaultFormat; |
| 45 | + |
| 46 | + return $this->getSerializer($format)->denormalize($data, $type, $format, $context); |
| 47 | + } |
| 48 | + |
| 49 | + public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool |
| 50 | + { |
| 51 | + $format ??= $this->defaultFormat; |
| 52 | + |
| 53 | + return $this->getSerializer($format)->supportsNormalization($data, $format, $context); |
| 54 | + } |
| 55 | + |
| 56 | + public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool |
| 57 | + { |
| 58 | + $format ??= $this->defaultFormat; |
| 59 | + |
| 60 | + return $this->getSerializer($format)->supportsDenormalization($data, $type, $format, $context); |
| 61 | + } |
| 62 | + |
| 63 | + public function encode(mixed $data, string $format, array $context = []) |
| 64 | + { |
| 65 | + $format ??= $this->defaultFormat; |
| 66 | + |
| 67 | + return $this->getSerializer($format)->encode($data, $format, $context); |
| 68 | + } |
| 69 | + |
| 70 | + public function decode(string $data, string $format, array $context = []) |
| 71 | + { |
| 72 | + $format ??= $this->defaultFormat; |
| 73 | + |
| 74 | + return $this->getSerializer($format)->decode($data, $format, $context); |
| 75 | + } |
| 76 | + |
| 77 | + public function supportsEncoding(string $format, array $context = []): bool |
| 78 | + { |
| 79 | + $format ??= $this->defaultFormat; |
| 80 | + |
| 81 | + return $this->getSerializer($format)->supportsEncoding($format, $context); |
| 82 | + } |
| 83 | + |
| 84 | + public function supportsDecoding(string $format, array $context = []): bool |
| 85 | + { |
| 86 | + $format ??= $this->defaultFormat; |
| 87 | + |
| 88 | + return $this->getSerializer($format)->supportsDecoding($format, $context); |
| 89 | + } |
40 | 90 | }
|
0 commit comments