@@ -45,36 +45,28 @@ public function createFromRequest(Request $request, bool $normalization, array $
45
45
46
46
$ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ attributes ['resource_class ' ]);
47
47
$ key = $ normalization ? 'normalization_context ' : 'denormalization_context ' ;
48
-
49
- $ operationKey = null ;
50
- $ operationType = null ;
51
-
52
48
if (isset ($ attributes ['collection_operation_name ' ])) {
53
49
$ operationKey = 'collection_operation_name ' ;
54
50
$ operationType = OperationType::COLLECTION ;
55
- } elseif (isset ($ attributes ['subresource_operation_name ' ])) {
51
+ } elseif (isset ($ attributes ['item_operation_name ' ])) {
52
+ $ operationKey = 'item_operation_name ' ;
53
+ $ operationType = OperationType::ITEM ;
54
+ } else {
56
55
$ operationKey = 'subresource_operation_name ' ;
57
56
$ operationType = OperationType::SUBRESOURCE ;
58
57
}
59
58
60
- if (null !== $ operationKey ) {
61
- $ attribute = $ attributes [$ operationKey ];
62
- $ context = $ resourceMetadata ->getCollectionOperationAttribute ($ attribute , $ key , [], true );
63
- $ context [$ operationKey ] = $ attribute ;
64
- } else {
65
- $ context = $ resourceMetadata ->getItemOperationAttribute ($ attributes ['item_operation_name ' ], $ key , [], true );
66
- $ context ['item_operation_name ' ] = $ attributes ['item_operation_name ' ];
67
- }
68
-
69
- $ context ['operation_type ' ] = $ operationType ?: OperationType::ITEM ;
59
+ $ context = $ resourceMetadata ->getTypedOperationAttribute ($ operationType , $ attributes [$ operationKey ], $ key , [], true );
60
+ $ context ['operation_type ' ] = $ operationType ;
61
+ $ context [$ operationKey ] = $ attributes [$ operationKey ];
70
62
71
63
if (!$ normalization && !isset ($ context ['api_allow_update ' ])) {
72
64
$ context ['api_allow_update ' ] = \in_array ($ request ->getMethod (), ['PUT ' , 'PATCH ' ], true );
73
65
}
74
66
75
67
$ context ['resource_class ' ] = $ attributes ['resource_class ' ];
76
- $ context ['input_class ' ] = $ attributes ['input_class ' ] ?? $ attributes ['resource_class ' ];
77
- $ context ['output_class ' ] = $ attributes ['output_class ' ] ?? $ attributes ['resource_class ' ];
68
+ $ context ['input_class ' ] = $ resourceMetadata -> getTypedOperationAttribute ( $ operationKey , $ attributes [$ operationKey ], 'input_class ' , $ attributes ['resource_class ' ], true ) ;
69
+ $ context ['output_class ' ] = $ resourceMetadata -> getTypedOperationAttribute ( $ operationKey , $ attributes [$ operationKey ], 'output_class ' , $ attributes ['resource_class ' ], true ) ;
78
70
$ context ['request_uri ' ] = $ request ->getRequestUri ();
79
71
$ context ['uri ' ] = $ request ->getUri ();
80
72
0 commit comments