44 * See COPYING.txt for license details.
55 */
66
7+ declare (strict_types=1 );
8+
79namespace Magento \Webapi \Controller \Soap \Request ;
810
11+ use InvalidArgumentException ;
912use Magento \Framework \Api \ExtensibleDataInterface ;
1013use Magento \Framework \Api \MetadataObjectInterface ;
1114use Magento \Framework \Api \SimpleDataObjectConverter ;
1215use Magento \Framework \App \ObjectManager ;
16+ use Magento \Framework \ObjectManagerInterface ;
1317use Magento \Framework \Webapi \Authorization ;
1418use Magento \Framework \Exception \AuthorizationException ;
1519use Magento \Framework \Reflection \DataObjectProcessor ;
1620use Magento \Framework \Webapi \ServiceInputProcessor ;
17- use Magento \Framework \Webapi \Request as SoapRequest ;
21+ use Magento \Framework \Webapi \Request as WebapiRequest ;
1822use Magento \Framework \Webapi \Exception as WebapiException ;
23+ use Magento \Framework \Webapi \Validator \EntityArrayValidator \InputArraySizeLimitValue ;
1924use Magento \Webapi \Controller \Rest \ParamsOverrider ;
2025use Magento \Webapi \Model \Soap \Config as SoapConfig ;
2126use Magento \Framework \Reflection \MethodsMap ;
3035 */
3136class Handler
3237{
33- const RESULT_NODE_NAME = 'result ' ;
38+ public const RESULT_NODE_NAME = 'result ' ;
3439
3540 /**
36- * @var \Magento\Framework\Webapi\Request
41+ * @var WebapiRequest
3742 */
3843 protected $ _request ;
3944
4045 /**
41- * @var \Magento\Framework\ ObjectManagerInterface
46+ * @var ObjectManagerInterface
4247 */
4348 protected $ _objectManager ;
4449
4550 /**
46- * @var \Magento\Webapi\Model\Soap\Config
51+ * @var SoapConfig
4752 */
4853 protected $ _apiConfig ;
4954
5055 /**
51- * @var \Magento\Framework\Webapi\ Authorization
56+ * @var Authorization
5257 */
5358 protected $ authorization ;
5459
5560 /**
56- * @var \Magento\Framework\Api\ SimpleDataObjectConverter
61+ * @var SimpleDataObjectConverter
5762 */
5863 protected $ _dataObjectConverter ;
5964
6065 /**
61- * @var \Magento\Framework\Webapi\ ServiceInputProcessor
66+ * @var ServiceInputProcessor
6267 */
6368 protected $ serviceInputProcessor ;
6469
6570 /**
66- * @var \Magento\Framework\Reflection\ DataObjectProcessor
71+ * @var DataObjectProcessor
6772 */
6873 protected $ _dataObjectProcessor ;
6974
7075 /**
71- * @var \Magento\Framework\Reflection\ MethodsMap
76+ * @var MethodsMap
7277 */
7378 protected $ methodsMapProcessor ;
7479
@@ -77,29 +82,37 @@ class Handler
7782 */
7883 private $ paramsOverrider ;
7984
85+ /**
86+ * @var InputArraySizeLimitValue
87+ */
88+ private $ inputArraySizeLimitValue ;
89+
8090 /**
8191 * Initialize dependencies.
8292 *
83- * @param SoapRequest $request
84- * @param \Magento\Framework\ ObjectManagerInterface $objectManager
93+ * @param WebapiRequest $request
94+ * @param ObjectManagerInterface $objectManager
8595 * @param SoapConfig $apiConfig
8696 * @param Authorization $authorization
8797 * @param SimpleDataObjectConverter $dataObjectConverter
8898 * @param ServiceInputProcessor $serviceInputProcessor
8999 * @param DataObjectProcessor $dataObjectProcessor
90100 * @param MethodsMap $methodsMapProcessor
91101 * @param ParamsOverrider|null $paramsOverrider
102+ * @param InputArraySizeLimitValue|null $inputArraySizeLimitValue
103+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
92104 */
93105 public function __construct (
94- SoapRequest $ request ,
95- \ Magento \ Framework \ ObjectManagerInterface $ objectManager ,
106+ WebapiRequest $ request ,
107+ ObjectManagerInterface $ objectManager ,
96108 SoapConfig $ apiConfig ,
97109 Authorization $ authorization ,
98110 SimpleDataObjectConverter $ dataObjectConverter ,
99111 ServiceInputProcessor $ serviceInputProcessor ,
100112 DataObjectProcessor $ dataObjectProcessor ,
101113 MethodsMap $ methodsMapProcessor ,
102- ?ParamsOverrider $ paramsOverrider = null
114+ ?ParamsOverrider $ paramsOverrider = null ,
115+ ?InputArraySizeLimitValue $ inputArraySizeLimitValue = null
103116 ) {
104117 $ this ->_request = $ request ;
105118 $ this ->_objectManager = $ objectManager ;
@@ -110,6 +123,8 @@ public function __construct(
110123 $ this ->_dataObjectProcessor = $ dataObjectProcessor ;
111124 $ this ->methodsMapProcessor = $ methodsMapProcessor ;
112125 $ this ->paramsOverrider = $ paramsOverrider ?? ObjectManager::getInstance ()->get (ParamsOverrider::class);
126+ $ this ->inputArraySizeLimitValue = $ inputArraySizeLimitValue ?? ObjectManager::getInstance ()
127+ ->get (InputArraySizeLimitValue::class);
113128 }
114129
115130 /**
@@ -144,10 +159,24 @@ public function __call($operation, $arguments)
144159 }
145160 $ service = $ this ->_objectManager ->get ($ serviceClass );
146161 $ inputData = $ this ->prepareOperationInput ($ serviceClass , $ serviceMethodInfo , $ arguments );
147- $ outputData = call_user_func_array ([ $ service , $ serviceMethod] , $ inputData );
162+ $ outputData = $ this -> runServiceMethod ( $ service , $ serviceMethod , $ inputData );
148163 return $ this ->_prepareResponseData ($ outputData , $ serviceClass , $ serviceMethod );
149164 }
150165
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+
151180 /**
152181 * Convert arguments received from SOAP server to arguments to pass to a service.
153182 *
@@ -156,14 +185,14 @@ public function __call($operation, $arguments)
156185 * @param array $arguments
157186 * @return array
158187 * @throws WebapiException
159- * @throws \Magento\Framework\Exception\InputException
160188 */
161189 private function prepareOperationInput (string $ serviceClass , array $ methodMetadata , array $ arguments ): array
162190 {
163191 /** SoapServer wraps parameters into array. Thus this wrapping should be removed to get access to parameters. */
164192 $ arguments = reset ($ arguments );
165193 $ arguments = $ this ->_dataObjectConverter ->convertStdObjectToArray ($ arguments , true );
166194 $ arguments = $ this ->paramsOverrider ->override ($ arguments , $ methodMetadata [ServiceMetadata::KEY_ROUTE_PARAMS ]);
195+ $ this ->inputArraySizeLimitValue ->set ($ methodMetadata [ServiceMetadata::KEY_INPUT_ARRAY_SIZE_LIMIT ]);
167196
168197 return $ this ->serviceInputProcessor ->process (
169198 $ serviceClass ,
@@ -179,8 +208,9 @@ private function prepareOperationInput(string $serviceClass, array $methodMetada
179208 * @param string $serviceMethod
180209 * @param array $arguments
181210 * @return array
182- * @deprecated 100.3.2
211+ * @throws WebapiException
183212 * @see Handler::prepareOperationInput()
213+ * @deprecated 100.3.2
184214 */
185215 protected function _prepareRequestData ($ serviceClass , $ serviceMethod , $ arguments )
186216 {
@@ -198,7 +228,7 @@ protected function _prepareRequestData($serviceClass, $serviceMethod, $arguments
198228 * @param string $serviceClassName
199229 * @param string $serviceMethodName
200230 * @return array
201- * @throws \ InvalidArgumentException
231+ * @throws InvalidArgumentException
202232 */
203233 protected function _prepareResponseData ($ data , $ serviceClassName , $ serviceMethodName )
204234 {
@@ -225,7 +255,7 @@ protected function _prepareResponseData($data, $serviceClassName, $serviceMethod
225255 } elseif (is_scalar ($ data ) || $ data === null ) {
226256 $ result = $ data ;
227257 } else {
228- throw new \ InvalidArgumentException ("Service returned result in invalid format. " );
258+ throw new InvalidArgumentException ("Service returned result in invalid format. " );
229259 }
230260 return [self ::RESULT_NODE_NAME => $ result ];
231261 }
0 commit comments