1818use ApiPlatform \Core \DataProvider \SubresourceDataProviderInterface ;
1919use ApiPlatform \Core \Exception \InvalidIdentifierException ;
2020use ApiPlatform \Core \Exception \RuntimeException ;
21- use ApiPlatform \Core \Identifier \Normalizer \ChainIdentifierNormalizer ;
21+ use ApiPlatform \Core \Identifier \Normalizer \ChainIdentifierDenormalizer ;
2222use ApiPlatform \Core \Serializer \SerializerContextBuilderInterface ;
2323use ApiPlatform \Core \Util \RequestAttributesExtractor ;
2424use ApiPlatform \Core \Util \RequestParser ;
2525use Symfony \Component \HttpFoundation \Request ;
2626use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
2727use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
28- use Symfony \Component \Serializer \Normalizer \DenormalizerInterface ;
2928
3029/**
3130 * Retrieves data from the applicable data provider and sets it as a request parameter called data.
@@ -38,20 +37,20 @@ final class ReadListener
3837 private $ itemDataProvider ;
3938 private $ subresourceDataProvider ;
4039 private $ serializerContextBuilder ;
41- private $ identifierNormalizer ;
40+ private $ identifierDenormalizer ;
4241
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 )
4443 {
4544 $ this ->collectionDataProvider = $ collectionDataProvider ;
4645 $ this ->itemDataProvider = $ itemDataProvider ;
4746 $ this ->subresourceDataProvider = $ subresourceDataProvider ;
4847 $ this ->serializerContextBuilder = $ serializerContextBuilder ;
4948
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 );
5251 }
5352
54- $ this ->identifierNormalizer = $ identifierNormalizer ;
53+ $ this ->identifierDenormalizer = $ identifierDenormalizer ;
5554 }
5655
5756 /**
@@ -122,9 +121,9 @@ private function getItemData(Request $request, array $attributes, array $context
122121 $ context = [];
123122
124123 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 ];
128127 }
129128
130129 $ 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 $
155154
156155 $ attributes ['subresource_context ' ] += $ context ;
157156 $ 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 ;
160159 }
161160
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+ }
167165
168- $ identifiers [$ id ] = $ request ->attributes ->get ($ id );
166+ $ identifiers [$ id ] = $ request ->attributes ->get ($ id );
169167
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 ' );
172173 }
173174 }
174- } catch (InvalidIdentifierException $ e ) {
175- throw new NotFoundHttpException ('Not Found ' );
176175 }
177176
178177 $ data = $ this ->subresourceDataProvider ->getSubresource ($ attributes ['resource_class ' ], $ identifiers , $ attributes ['subresource_context ' ], $ attributes ['subresource_operation_name ' ]);
0 commit comments