12
12
namespace Symfony \Component \Serializer \Normalizer ;
13
13
14
14
use Symfony \Component \PropertyAccess \PropertyAccess ;
15
+ use Symfony \Component \PropertyAccess \PropertyAccessor ;
15
16
use Symfony \Component \Serializer \Exception \NotNormalizableValueException ;
16
17
use Symfony \Component \Serializer \SerializerAwareInterface ;
17
18
use Symfony \Component \Serializer \SerializerInterface ;
18
19
19
- class UnwrappingDenormalizer implements DenormalizerInterface, SerializerAwareInterface
20
+ final class UnwrappingDenormalizer implements DenormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface
20
21
{
21
22
const UNWRAP_PATH = 'unwrap_path ' ;
22
23
@@ -30,20 +31,18 @@ class UnwrappingDenormalizer implements DenormalizerInterface, SerializerAwareIn
30
31
*/
31
32
private $ propertyAccess ;
32
33
33
- public function __construct ()
34
+ public function __construct (PropertyAccessor $ propertyAccess )
34
35
{
35
- $ this ->propertyAccess = PropertyAccess:: createPropertyAccessor () ;
36
+ $ this ->propertyAccess = $ propertyAccess ;
36
37
}
37
38
38
39
/**
39
40
* {@inheritdoc}
40
- *
41
- * @throws NotNormalizableValueException
42
41
*/
43
42
public function denormalize ($ data , $ class , $ format = null , array $ context = [])
44
43
{
45
44
$ propertyPath = $ context [self ::UNWRAP_PATH ];
46
- unset( $ context [self :: UNWRAP_PATH ]) ;
45
+ $ context ['
8000
unwrapped ' ] = true ;
47
46
48
47
if ($ propertyPath ) {
49
48
if (!$ this ->propertyAccess ->isReadable ($ data , $ propertyPath )) {
@@ -61,7 +60,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
61
60
*/
62
61
public function supportsDenormalization ($ data , $ type , $ format = null , array $ context = [])
63
62
{
64
- return \array_key_exists (self ::UNWRAP_PATH , $ context );
63
+ return \array_key_exists (self ::UNWRAP_PATH , $ context ) && ! isset ( $ context [ ' unwrapped ' ]) ;
65
64
}
66
65
67
66
/**
@@ -71,4 +70,12 @@ public function setSerializer(SerializerInterface $serializer)
71
70
{
72
71
$ this ->serializer = $ serializer ;
73
72
}
73
+
74
+ /**
75
+ * {@inheritdoc}
76
+ */
77
+ public function hasCacheableSupportsMethod (): bool
78
+ {
79
+ return $ this ->serializer instanceof CacheableSupportsMethodInterface && $ this ->serializer ->hasCacheableSupportsMethod ();
80
+ }
74
81
}
0 commit comments