18
18
use ApiPlatform \Core \DataProvider \SubresourceDataProviderInterface ;
19
19
use ApiPlatform \Core \Exception \InvalidIdentifierException ;
20
20
use ApiPlatform \Core \Exception \RuntimeException ;
21
- use ApiPlatform \Core \Identifier \Normalizer \ChainIdentifierNormalizer ;
21
+ use ApiPlatform \Core \Identifier \Normalizer \ChainIdentifierDenormalizer ;
22
22
use ApiPlatform \Core \Serializer \SerializerContextBuilderInterface ;
23
23
use ApiPlatform \Core \Util \RequestAttributesExtractor ;
24
24
use ApiPlatform \Core \Util \RequestParser ;
25
25
use Symfony \Component \HttpFoundation \Request ;
26
26
use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
27
27
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
28
- use Symfony \Component \Serializer \Normalizer \DenormalizerInterface ;
29
28
30
29
/**
31
30
* Retrieves data from the applicable data provider and sets it as a request parameter called data.
@@ -38,20 +37,20 @@ final class ReadListener
38
37
private $ itemDataProvider ;
39
38
private $ subresourceDataProvider ;
40
39
private $ serializerContextBuilder ;
41
- private $ identifierNormalizer ;
40
+ private $ identifierDenormalizer ;
42
41
43
- public function __construct (CollectionDataProviderInterface $ collectionDataProvider , ItemDataProviderInterface $ itemDataProvider , SubresourceDataProviderInterface $ subresourceDataProvider = null , SerializerContextBuilderInterface $ serializerContextBuilder = null , DenormalizerInterface $ identifierNormalizer = null )
42
+ public function __construct (CollectionDataProviderInterface $ collectionDataProvider , ItemDataProviderInterface $ itemDataProvider , SubresourceDataProviderInterface $ subresourceDataProvider = null , SerializerContextBuilderInterface $ serializerContextBuilder = null , ChainIdentifierDenormalizer $ identifierDenormalizer = null )
44
43
{
45
44
$ this ->collectionDataProvider = $ collectionDataProvider ;
46
45
$ this ->itemDataProvider = $ itemDataProvider ;
47
46
$ this ->subresourceDataProvider = $ subresourceDataProvider ;
48
47
$ this ->serializerContextBuilder = $ serializerContextBuilder ;
49
48
50
- if (null === $ identifierNormalizer ) {
51
- @trigger_error (sprintf ('Not injecting "%s" is deprecated since API Platform 2.2 and will not be possible anymore in API Platform 3. ' , ChainIdentifierNormalizer ::class), E_USER_DEPRECATED );
49
+ if (null === $ identifierDenormalizer ) {
50
+ @trigger_error (sprintf ('Not injecting "%s" is deprecated since API Platform 2.2 and will not be possible anymore in API Platform 3. ' , ChainIdentifierDenormalizer ::class), E_USER_DEPRECATED );
52
51
}
53
52
54
- $ this ->identifierNormalizer = $ identifierNormalizer ;
53
+ $ this ->identifierDenormalizer = $ identifierDenormalizer ;
55
54
}
56
55
57
56
/**
@@ -122,9 +121,9 @@ private function getItemData(Request $request, array $attributes, array $context
122
121
$ context = [];
123
122
124
123
try {
125
- if ($ this ->identifierNormalizer ) {
126
- $ id = $ this ->identifierNormalizer ->denormalize ((string ) $ id , $ attributes ['resource_class ' ]);
127
- $ context = [ChainIdentifierNormalizer:: HAS_IDENTIFIER_NORMALIZER => true ];
124
+ if ($ this ->identifierDenormalizer ) {
125
+ $ id = $ this ->identifierDenormalizer ->denormalize ((string ) $ id , $ attributes ['resource_class ' ]);
126
+ $ context = [ChainIdentifierDenormalizer:: HAS_IDENTIFIER_DENORMALIZER => true ];
128
127
}
129
128
130
129
$ data = $ this ->itemDataProvider ->getItem ($ attributes ['resource_class ' ], $ id , $ attributes ['item_operation_name ' ], $ context );
@@ -155,24 +154,24 @@ private function getSubresourceData(Request $request, array $attributes, array $
155
154
156
155
$ attributes ['subresource_context ' ] += $ context ;
157
156
$ identifiers = [];
158
- if ($ this ->identifierNormalizer ) {
159
- $ attributes ['subresource_context ' ][ChainIdentifierNormalizer:: HAS_IDENTIFIER_NORMALIZER ] = true ;
157
+ if ($ this ->identifierDenormalizer ) {
158
+ $ attributes ['subresource_context ' ][ChainIdentifierDenormalizer:: HAS_IDENTIFIER_DENORMALIZER ] = true ;
160
159
}
161
160
162
- try {
163
- foreach ($ attributes ['subresource_context ' ]['identifiers ' ] as $ key => list ($ id , $ resourceClass , $ hasIdentifier )) {
164
- if (false === $ hasIdentifier ) {
165
- continue ;
166
- }
161
+ foreach ($ attributes ['subresource_context ' ]['identifiers ' ] as $ key => list ($ id , $ resourceClass , $ hasIdentifier )) {
162
+ if (false === $ hasIdentifier ) {
163
+ continue ;
164
+ }
167
165
168
- $ identifiers [$ id ] = $ request ->attributes ->get ($ id );
166
+ $ identifiers [$ id ] = $ request ->attributes ->get ($ id );
169
167
170
- if ($ this ->identifierNormalizer ) {
171
- $ identifiers [$ id ] = $ this ->identifierNormalizer ->denormalize ((string ) $ identifiers [$ id ], $ resourceClass );
168
+ if ($ this ->identifierDenormalizer ) {
169
+ try {
170
+ $ identifiers [$ id ] = $ this ->identifierDenormalizer ->denormalize ((string ) $ identifiers [$ id ], $ resourceClass );
171
+ } catch (InvalidIdentifierException $ e ) {
172
+ throw new NotFoundHttpException ('Not Found ' );
172
173
}
173
174
}
174
- } catch (InvalidIdentifierException $ e ) {
175
- throw new NotFoundHttpException ('Not Found ' );
176
175
}
177
176
178
177
$ data = $ this ->subresourceDataProvider ->getSubresource ($ attributes ['resource_class ' ], $ identifiers , $ attributes ['subresource_context ' ], $ attributes ['subresource_operation_name ' ]);
0 commit comments