@@ -39,27 +39,33 @@ public static function createDefault(): DataConverterInterface
3939 );
4040 }
4141
42- public function fromPayload (Payload $ payload , $ type )
42+ /**
43+ * @param string|\ReflectionClass|\ReflectionType|Type|null $type
44+ */
45+ public function fromPayload (Payload $ payload , $ type ): mixed
4346 {
47+ $ type = Type::create ($ type );
48+
49+ if ($ type ->isClass () && $ type ->getName () === RawValue::class) {
50+ return new RawValue ($ payload );
51+ }
52+
4453 /** @var \ArrayAccess $meta */
4554 $ meta = $ payload ->getMetadata ();
4655
4756 $ encoding = $ meta [EncodingKeys::METADATA_ENCODING_KEY ];
4857
4958 if (!isset ($ this ->converters [$ encoding ])) {
50- throw new DataConverterException (\sprintf ('Undefined payload encoding %s ' , $ encoding ));
59+ throw new DataConverterException (\sprintf ('Undefined payload encoding "%s" ' , $ encoding ));
5160 }
5261
53- $ type = Type::create ($ type );
54- if (\in_array ($ type ->getName (), [Type::TYPE_VOID , Type::TYPE_NULL , Type::TYPE_FALSE , Type::TYPE_TRUE ], true )) {
55- return match ($ type ->getName ()) {
56- Type::TYPE_VOID , Type::TYPE_NULL => null ,
57- Type::TYPE_TRUE => true ,
58- Type::TYPE_FALSE => false ,
59- };
60- }
61-
62- return $ this ->converters [$ encoding ]->fromPayload ($ payload , $ type );
62+ return match ($ type ->getName ()) {
63+ Type::TYPE_VOID ,
64+ Type::TYPE_NULL => null ,
65+ Type::TYPE_TRUE => true ,
66+ Type::TYPE_FALSE => false ,
67+ default => $ this ->converters [$ encoding ]->fromPayload ($ payload , $ type ),
68+ };
6369 }
6470
6571 /**
@@ -69,6 +75,9 @@ public function fromPayload(Payload $payload, $type)
6975 */
7076 public function toPayload ($ value ): Payload
7177 {
78+ if ($ value instanceof RawValue) {
79+ return $ value ->getPayload ();
80+ }
7281 foreach ($ this ->converters as $ converter ) {
7382 $ payload = $ converter ->toPayload ($ value );
7483
0 commit comments