@@ -69,15 +69,11 @@ public function __construct(PropertyNameCollectionFactoryInterface $propertyName
69
69
*/
70
70
public function applyToCollection (QueryBuilder $ queryBuilder , QueryNameGeneratorInterface $ queryNameGenerator , string $ resourceClass , string $ operationName = null )
71
71
{
72
- $ options = [];
73
-
74
- if (null !== $ operationName ) {
75
- $ options = ['collection_operation_name ' => $ operationName ];
76
- }
72
+ $ options = null === $ operationName ? [] : ['collection_operation_name ' => $ operationName ];
77
73
78
74
$ forceEager = $ this ->shouldOperationForceEager ($ resourceClass , $ options );
79
75
$ fetchPartial = $ this ->shouldOperationFetchPartial ($ resourceClass , $ options );
80
- $ serializerContext = $ this ->getSerializerContext ($ resourceClass , 'normalization_context ' , $ options );
76
+ $ serializerContext = $ this ->getPropertyMetadataOptions ($ resourceClass , 'normalization_context ' , $ options );
81
77
82
78
$ groups = $ this ->getSerializerGroups ($ options , $ serializerContext );
83
79
@@ -89,19 +85,15 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
89
85
*/
90
86
public function applyToItem (QueryBuilder $ queryBuilder , QueryNameGeneratorInterface $ queryNameGenerator , string $ resourceClass , array $ identifiers , string $ operationName = null , array $ context = [])
91
87
{
92
- $ options = [];
93
-
94
- if (null !== $ operationName ) {
95
- $ options = ['item_operation_name ' => $ operationName ];
96
- }
88
+ $ options = null === $ operationName ? [] : ['item_operation_name ' => $ operationName ];
97
89
98
90
$ forceEager = $ this ->shouldOperationForceEager ($ resourceClass , $ options );
99
91
$ fetchPartial = $ this ->shouldOperationFetchPartial ($ resourceClass , $ options );
100
92
$ contextType = isset ($ context ['api_denormalize ' ]) ? 'denormalization_context ' : 'normalization_context ' ;
101
- $ serializerContext = $ this ->getSerializerContext ($ context ['resource_class ' ] ?? $ resourceClass , $ contextType , $ options );
102
- $ groups = $ this ->getSerializerGroups ($ options , $ serializerContext );
93
+ $ propertyMetadataOptions = $ this ->getPropertyMetadataOptions ($ context ['resource_class ' ] ?? $ resourceClass , $ contextType , $ options );
94
+ $ serializerGroups = $ this ->getSerializerGroups ($ options , $ propertyMetadataOptions );
103
95
104
- $ this ->joinRelations ($ queryBuilder , $ queryNameGenerator , $ resourceClass , $ forceEager , $ fetchPartial , $ queryBuilder ->getRootAliases ()[0 ], $ groups , $ serializerContext );
96
+ $ this ->joinRelations ($ queryBuilder , $ queryNameGenerator , $ resourceClass , $ forceEager , $ fetchPartial , $ queryBuilder ->getRootAliases ()[0 ], $ serializerGroups , $ propertyMetadataOptions );
105
97
}
106
98
107
99
/**
@@ -231,10 +223,9 @@ private function addSelect(QueryBuilder $queryBuilder, string $entity, string $a
231
223
* @param string $contextType normalization_context or denormalization_context
232
224
* @param array $options represents the operation name so that groups are the one of the specific operation
233
225
*/
234
- private function getSerializerContext (string $ resourceClass , string $ contextType , array $ options ): array
226
+ private function getPropertyMetadataOptions (string $ resourceClass , string $ contextType , array $ options ): array
235
227
{
236
228
$ request = null ;
237
-
238
229
if (null !== $ this ->requestStack && null !== $ this ->serializerContextBuilder ) {
239
230
$ request = $ this ->requestStack ->getCurrentRequest ();
240
231
}
@@ -244,7 +235,6 @@ private function getSerializerContext(string $resourceClass, string $contextType
244
235
}
245
236
246
237
$ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ resourceClass );
247
-
248
238
if (isset ($ options ['collection_operation_name ' ])) {
249
239
$ context = $ resourceMetadata ->getCollectionOperationAttribute ($ options ['collection_operation_name ' ], $ contextType , null , true );
250
240
} elseif (isset ($ options ['item_operation_name ' ])) {
@@ -263,10 +253,10 @@ private function getSerializerContext(string $resourceClass, string $contextType
263
253
*/
264
254
private function getSerializerGroups (array $ options , array $ context ): array
265
255
{
266
- if (empty ($ context [AbstractNormalizer::GROUPS ])) {
267
- return $ options ;
256
+ if (! empty ($ context [AbstractNormalizer::GROUPS ])) {
257
+ $ options[ ' serializer_groups ' ] = $ context [AbstractNormalizer:: GROUPS ] ;
268
258
}
269
259
270
- return [ ' serializer_groups ' => $ context [AbstractNormalizer:: GROUPS ]] ;
260
+ return $ options ;
271
261
}
272
262
}
0 commit comments