5
5
*/
6
6
namespace Magento \Webapi \Controller ;
7
7
8
- use Magento \Authorization \Model \UserContextInterface ;
9
8
use Magento \Framework \AuthorizationInterface ;
10
9
use Magento \Framework \Exception \AuthorizationException ;
11
10
use Magento \Framework \Webapi \ErrorProcessor ;
14
13
use Magento \Framework \Webapi \Rest \Request as RestRequest ;
15
14
use Magento \Framework \Webapi \Rest \Response as RestResponse ;
16
15
use Magento \Framework \Webapi \Rest \Response \FieldsFilter ;
16
+ use Magento \Webapi \Controller \Rest \ParamsOverrider ;
17
17
use Magento \Webapi \Controller \Rest \Router ;
18
18
use Magento \Webapi \Controller \Rest \Router \Route ;
19
- use Magento \Webapi \Model \Config \Converter ;
20
19
21
20
/**
22
21
* Front controller for WebAPI REST area.
@@ -93,9 +92,9 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface
93
92
protected $ session ;
94
93
95
94
/**
96
- * @var \Magento\Authorization\Model\UserContextInterface
95
+ * @var ParamsOverrider
97
96
*/
98
- protected $ userContext ;
97
+ protected $ paramsOverrider ;
99
98
100
99
/**
101
100
* @var ServiceOutputProcessor $serviceOutputProcessor
@@ -116,7 +115,7 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface
116
115
* @param PathProcessor $pathProcessor
117
116
* @param \Magento\Framework\App\AreaList $areaList
118
117
* @param FieldsFilter $fieldsFilter
119
- * @param UserContextInterface $userContext
118
+ * @param ParamsOverrider $paramsOverrider
120
119
* @param ServiceOutputProcessor $serviceOutputProcessor
121
120
*
122
121
* TODO: Consider removal of warning suppression
@@ -134,7 +133,7 @@ public function __construct(
134
133
PathProcessor $ pathProcessor ,
135
134
\Magento \Framework \App \AreaList $ areaList ,
136
135
FieldsFilter $ fieldsFilter ,
137
- UserContextInterface $ userContext ,
136
+ ParamsOverrider $ paramsOverrider ,
138
137
ServiceOutputProcessor $ serviceOutputProcessor
139
138
) {
140
139
$ this ->_router = $ router ;
@@ -148,7 +147,7 @@ public function __construct(
148
147
$ this ->_pathProcessor = $ pathProcessor ;
149
148
$ this ->areaList = $ areaList ;
150
149
$ this ->fieldsFilter = $ fieldsFilter ;
151
- $ this ->userContext = $ userContext ;
150
+ $ this ->paramsOverrider = $ paramsOverrider ;
152
151
$ this ->serviceOutputProcessor = $ serviceOutputProcessor ;
153
152
}
154
153
@@ -174,7 +173,7 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
174
173
$ inputData = $ this ->_request ->getRequestData ();
175
174
$ serviceMethodName = $ route ->getServiceMethod ();
176
175
$ serviceClassName = $ route ->getServiceClass ();
177
- $ inputData = $ this ->overrideParams ($ inputData , $ route ->getParameters ());
176
+ $ inputData = $ this ->paramsOverrider -> override ($ inputData , $ route ->getParameters ());
178
177
$ inputParams = $ this ->serviceInputProcessor ->process ($ serviceClassName , $ serviceMethodName , $ inputData );
179
178
$ service = $ this ->_objectManager ->get ($ serviceClassName );
180
179
/** @var \Magento\Framework\Api\AbstractExtensibleObject $outputData */
@@ -195,74 +194,6 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
195
194
return $ this ->_response ;
196
195
}
197
196
198
- /**
199
- * Override parameter values based on webapi.xml
200
- *
201
- * @param array $inputData Incoming data from request
202
- * @param array $parameters Contains parameters to replace or default
203
- * @return array Data in same format as $inputData with appropriate parameters added or changed
204
- */
205
- protected function overrideParams (array $ inputData , array $ parameters )
206
- {
207
- foreach ($ parameters as $ name => $ paramData ) {
208
- $ arrayKeys = explode ('. ' , $ name );
209
- if ($ paramData [Converter::KEY_FORCE ] || !$ this ->isNestedArrayValueSet ($ inputData , $ arrayKeys )) {
210
- if ($ paramData [Converter::KEY_VALUE ] == '%customer_id% '
211
- && $ this ->userContext ->getUserType () === UserContextInterface::USER_TYPE_CUSTOMER
212
- ) {
213
- $ value = $ this ->userContext ->getUserId ();
214
- } else {
215
- $ value = $ paramData [Converter::KEY_VALUE ];
216
- }
217
- $ this ->setNestedArrayValue ($ inputData , $ arrayKeys , $ value );
218
- }
219
- }
220
- return $ inputData ;
221
- }
222
-
223
- /**
224
- * Determine if a nested array value is set.
225
- *
226
- * @param array &$nestedArray
227
- * @param string[] $arrayKeys
228
- * @return bool true if array value is set
229
- */
230
- protected function isNestedArrayValueSet (&$ nestedArray , $ arrayKeys )
231
- {
232
- $ currentArray = &$ nestedArray ;
233
-
234
- foreach ($ arrayKeys as $ key ) {
235
- if (!isset ($ currentArray [$ key ])) {
236
- return false ;
237
- }
238
- $ currentArray = &$ currentArray [$ key ];
239
- }
240
- return true ;
241
- }
242
-
243
- /**
244
- * Set a nested array value.
245
- *
246
- * @param array &$nestedArray
247
- * @param string[] $arrayKeys
248
- * @param string $valueToSet
249
- * @return void
250
- */
251
- protected function setNestedArrayValue (&$ nestedArray , $ arrayKeys , $ valueToSet )
252
- {
253
- $ currentArray = &$ nestedArray ;
254
- $ lastKey = array_pop ($ arrayKeys );
255
-
256
- foreach ($ arrayKeys as $ key ) {
257
- if (!isset ($ currentArray [$ key ])) {
258
- $ currentArray [$ key ] = [];
259
- }
260
- $ currentArray = &$ currentArray [$ key ];
261
- }
262
-
263
- $ currentArray [$ lastKey ] = $ valueToSet ;
264
- }
265
-
266
197
/**
267
198
* Retrieve current route.
268
199
*
0 commit comments