4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
+ declare (strict_types=1 );
8
+
7
9
namespace Magento \Webapi \Controller \Soap \Request ;
8
10
11
+ use InvalidArgumentException ;
9
12
use Magento \Framework \Api \ExtensibleDataInterface ;
10
13
use Magento \Framework \Api \MetadataObjectInterface ;
11
14
use Magento \Framework \Api \SimpleDataObjectConverter ;
12
15
use Magento \Framework \App \ObjectManager ;
16
+ use Magento \Framework \ObjectManagerInterface ;
13
17
use Magento \Framework \Webapi \Authorization ;
14
18
use Magento \Framework \Exception \AuthorizationException ;
15
19
use Magento \Framework \Reflection \DataObjectProcessor ;
16
20
use Magento \Framework \Webapi \ServiceInputProcessor ;
17
- use Magento \Framework \Webapi \Request as SoapRequest ;
21
+ use Magento \Framework \Webapi \Request as WebapiRequest ;
18
22
use Magento \Framework \Webapi \Exception as WebapiException ;
23
+ use Magento \Framework \Webapi \Validator \EntityArrayValidator \InputArraySizeLimitValue ;
19
24
use Magento \Webapi \Controller \Rest \ParamsOverrider ;
20
25
use Magento \Webapi \Model \Soap \Config as SoapConfig ;
21
26
use Magento \Framework \Reflection \MethodsMap ;
30
35
*/
31
36
class Handler
32
37
{
33
- const RESULT_NODE_NAME = 'result ' ;
38
+ public const RESULT_NODE_NAME = 'result ' ;
34
39
35
40
/**
36
- * @var \Magento\Framework\Webapi\Request
41
+ * @var WebapiRequest
37
42
*/
38
43
protected $ _request ;
39
44
40
45
/**
41
- * @var \Magento\Framework\ ObjectManagerInterface
46
+ * @var ObjectManagerInterface
42
47
*/
43
48
protected $ _objectManager ;
44
49
45
50
/**
46
- * @var \Magento\Webapi\Model\Soap\Config
51
+ * @var SoapConfig
47
52
*/
48
53
protected $ _apiConfig ;
49
54
50
55
/**
51
- * @var \Magento\Framework\Webapi\ Authorization
56
+ * @var Authorization
52
57
*/
53
58
protected $ authorization ;
54
59
55
60
/**
56
- * @var \Magento\Framework\Api\ SimpleDataObjectConverter
61
+ * @var SimpleDataObjectConverter
57
62
*/
58
63
protected $ _dataObjectConverter ;
59
64
60
65
/**
61
- * @var \Magento\Framework\Webapi\ ServiceInputProcessor
66
+ * @var ServiceInputProcessor
62
67
*/
63
68
protected $ serviceInputProcessor ;
64
69
65
70
/**
66
- * @var \Magento\Framework\Reflection\ DataObjectProcessor
71
+ * @var DataObjectProcessor
67
72
*/
68
73
protected $ _dataObjectProcessor ;
69
74
70
75
/**
71
- * @var \Magento\Framework\Reflection\ MethodsMap
76
+ * @var MethodsMap
72
77
*/
73
78
protected $ methodsMapProcessor ;
74
79
@@ -77,29 +82,37 @@ class Handler
77
82
*/
78
83
private $ paramsOverrider ;
79
84
85
+ /**
86
+ * @var InputArraySizeLimitValue
87
+ */
88
+ private $ inputArraySizeLimitValue ;
89
+
80
90
/**
81
91
* Initialize dependencies.
82
92
*
83
- * @param SoapRequest $request
84
- * @param \Magento\Framework\ ObjectManagerInterface $objectManager
93
+ * @param WebapiRequest $request
94
+ * @param ObjectManagerInterface $objectManager
85
95
* @param SoapConfig $apiConfig
86
96
* @param Authorization $authorization
87
97
* @param SimpleDataObjectConverter $dataObjectConverter
88
98
* @param ServiceInputProcessor $serviceInputProcessor
89
99
* @param DataObjectProcessor $dataObjectProcessor
90
100
* @param MethodsMap $methodsMapProcessor
91
101
* @param ParamsOverrider|null $paramsOverrider
102
+ * @param InputArraySizeLimitValue|null $inputArraySizeLimitValue
103
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
92
104
*/
93
105
public function __construct (
94
- SoapRequest $ request ,
95
- \ Magento \ Framework \ ObjectManagerInterface $ objectManager ,
106
+ WebapiRequest $ request ,
107
+ ObjectManagerInterface $ objectManager ,
96
108
SoapConfig $ apiConfig ,
97
109
Authorization $ authorization ,
98
110
SimpleDataObjectConverter $ dataObjectConverter ,
99
111
ServiceInputProcessor $ serviceInputProcessor ,
100
112
DataObjectProcessor $ dataObjectProcessor ,
101
113
MethodsMap $ methodsMapProcessor ,
102
- ?ParamsOverrider $ paramsOverrider = null
114
+ ?ParamsOverrider $ paramsOverrider = null ,
115
+ ?InputArraySizeLimitValue $ inputArraySizeLimitValue = null
103
116
) {
104
117
$ this ->_request = $ request ;
105
118
$ this ->_objectManager = $ objectManager ;
@@ -110,6 +123,8 @@ public function __construct(
110
123
$ this ->_dataObjectProcessor = $ dataObjectProcessor ;
111
124
$ this ->methodsMapProcessor = $ methodsMapProcessor ;
112
125
$ this ->paramsOverrider = $ paramsOverrider ?? ObjectManager::getInstance ()->get (ParamsOverrider::class);
126
+ $ this ->inputArraySizeLimitValue = $ inputArraySizeLimitValue ?? ObjectManager::getInstance ()
127
+ ->get (InputArraySizeLimitValue::class);
113
128
}
114
129
115
130
/**
@@ -144,10 +159,24 @@ public function __call($operation, $arguments)
144
159
}
145
160
$ service = $ this ->_objectManager ->get ($ serviceClass );
146
161
$ inputData = $ this ->prepareOperationInput ($ serviceClass , $ serviceMethodInfo , $ arguments );
147
- $ outputData = call_user_func_array ([ $ service , $ serviceMethod] , $ inputData );
162
+ $ outputData = $ this -> runServiceMethod ( $ service , $ serviceMethod , $ inputData );
148
163
return $ this ->_prepareResponseData ($ outputData , $ serviceClass , $ serviceMethod );
149
164
}
150
165
166
+ /**
167
+ * Runs service method
168
+ *
169
+ * @param object $service
170
+ * @param string $serviceMethod
171
+ * @param array $inputData
172
+ * @return false|mixed
173
+ */
174
+ private function runServiceMethod ($ service , $ serviceMethod , $ inputData )
175
+ {
176
+ // phpcs:ignore Magento2.Functions.DiscouragedFunction
177
+ return call_user_func_array ([$ service , $ serviceMethod ], $ inputData );
178
+ }
179
+
151
180
/**
152
181
* Convert arguments received from SOAP server to arguments to pass to a service.
153
182
*
@@ -156,14 +185,14 @@ public function __call($operation, $arguments)
156
185
* @param array $arguments
157
186
* @return array
158
187
* @throws WebapiException
159
- * @throws \Magento\Framework\Exception\InputException
160
188
*/
161
189
private function prepareOperationInput (string $ serviceClass , array $ methodMetadata , array $ arguments ): array
162
190
{
163
191
/** SoapServer wraps parameters into array. Thus this wrapping should be removed to get access to parameters. */
164
192
$ arguments = reset ($ arguments );
165
193
$ arguments = $ this ->_dataObjectConverter ->convertStdObjectToArray ($ arguments , true );
166
194
$ arguments = $ this ->paramsOverrider ->override ($ arguments , $ methodMetadata [ServiceMetadata::KEY_ROUTE_PARAMS ]);
195
+ $ this ->inputArraySizeLimitValue ->set ($ methodMetadata [ServiceMetadata::KEY_INPUT_ARRAY_SIZE_LIMIT ]);
167
196
168
197
return $ this ->serviceInputProcessor ->process (
169
198
$ serviceClass ,
@@ -179,8 +208,9 @@ private function prepareOperationInput(string $serviceClass, array $methodMetada
179
208
* @param string $serviceMethod
180
209
* @param array $arguments
181
210
* @return array
182
- * @deprecated 100.3.2
211
+ * @throws WebapiException
183
212
* @see Handler::prepareOperationInput()
213
+ * @deprecated 100.3.2
184
214
*/
185
215
protected function _prepareRequestData ($ serviceClass , $ serviceMethod , $ arguments )
186
216
{
@@ -198,7 +228,7 @@ protected function _prepareRequestData($serviceClass, $serviceMethod, $arguments
198
228
* @param string $serviceClassName
199
229
* @param string $serviceMethodName
200
230
* @return array
201
- * @throws \ InvalidArgumentException
231
+ * @throws InvalidArgumentException
202
232
*/
203
233
protected function _prepareResponseData ($ data , $ serviceClassName , $ serviceMethodName )
204
234
{
@@ -225,7 +255,7 @@ protected function _prepareResponseData($data, $serviceClassName, $serviceMethod
225
255
} elseif (is_scalar ($ data ) || $ data === null ) {
226
256
$ result = $ data ;
227
257
} else {
228
- throw new \ InvalidArgumentException ("Service returned result in invalid format. " );
258
+ throw new InvalidArgumentException ("Service returned result in invalid format. " );
229
259
}
230
260
return [self ::RESULT_NODE_NAME => $ result ];
231
261
}
0 commit comments