14
14
use Magento \Framework \Webapi \Request ;
15
15
use Magento \Framework \Webapi \Rest \Request as RestRequest ;
16
16
use Magento \Framework \Webapi \Rest \Response as RestResponse ;
17
- use Magento \Framework \Webapi \Rest \Response \FieldsFilter ;
18
17
use Magento \Framework \Webapi \ServiceInputProcessor ;
19
- use Magento \Framework \Webapi \ServiceOutputProcessor ;
20
18
use Magento \Store \Model \Store ;
21
19
use Magento \Store \Model \StoreManagerInterface ;
22
20
use Magento \Webapi \Controller \Rest \ParamsOverrider ;
23
21
use Magento \Webapi \Controller \Rest \Router ;
24
22
use Magento \Webapi \Controller \Rest \Router \Route ;
25
- use Magento \Webapi \Model \Rest \Swagger \ Generator ;
23
+ use Magento \Webapi \Controller \Rest \RequestProcessorPool ;
26
24
27
25
/**
28
26
* Front controller for WebAPI REST area.
32
30
*/
33
31
class Rest implements \Magento \Framework \App \FrontControllerInterface
34
32
{
35
- /** Path for accessing REST API schema */
33
+ /**
34
+ * Path for accessing REST API schema
35
+ *
36
+ * @deprecated 100.3.0
37
+ */
36
38
const SCHEMA_PATH = '/schema ' ;
37
39
38
40
/**
@@ -94,11 +96,6 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface
94
96
*/
95
97
protected $ areaList ;
96
98
97
- /**
98
- * @var \Magento\Framework\Webapi\Rest\Response\FieldsFilter
99
- */
100
- protected $ fieldsFilter ;
101
-
102
99
/**
103
100
* @var \Magento\Framework\Session\Generic
104
101
*/
@@ -111,31 +108,16 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface
111
108
protected $ paramsOverrider ;
112
109
113
110
/**
114
- * @var \Magento\Framework\Webapi\ServiceOutputProcessor
115
- */
116
- protected $ serviceOutputProcessor ;
117
-
118
- /**
119
- * @var \Magento\Webapi\Model\Rest\Swagger\Generator
111
+ * @var RequestProcessorPool
120
112
*/
121
- protected $ swaggerGenerator ;
113
+ protected $ requestProcessorPool ;
122
114
123
115
/**
124
116
* @var StoreManagerInterface
125
117
* @deprecated 100.1.0
126
118
*/
127
119
private $ storeManager ;
128
120
129
- /**
130
- * @var DeploymentConfig
131
- */
132
- private $ deploymentConfig ;
133
-
134
- /**
135
- * @var Rest\InputParamsResolver
136
- */
137
- private $ inputParamsResolver ;
138
-
139
121
/**
140
122
* Initialize dependencies
141
123
*
@@ -149,11 +131,9 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface
149
131
* @param ErrorProcessor $errorProcessor
150
132
* @param PathProcessor $pathProcessor
151
133
* @param \Magento\Framework\App\AreaList $areaList
152
- * @param FieldsFilter $fieldsFilter
153
134
* @param ParamsOverrider $paramsOverrider
154
- * @param ServiceOutputProcessor $serviceOutputProcessor
155
- * @param Generator $swaggerGenerator ,
156
135
* @param StoreManagerInterface $storeManager
136
+ * @param RequestProcessorPool $requestProcessorPool
157
137
*
158
138
* TODO: Consider removal of warning suppression
159
139
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -169,11 +149,9 @@ public function __construct(
169
149
ErrorProcessor $ errorProcessor ,
170
150
PathProcessor $ pathProcessor ,
171
151
\Magento \Framework \App \AreaList $ areaList ,
172
- FieldsFilter $ fieldsFilter ,
173
152
ParamsOverrider $ paramsOverrider ,
174
- ServiceOutputProcessor $ serviceOutputProcessor ,
175
- Generator $ swaggerGenerator ,
176
- StoreManagerInterface $ storeManager
153
+ StoreManagerInterface $ storeManager ,
154
+ RequestProcessorPool $ requestProcessorPool
177
155
) {
178
156
$ this ->_router = $ router ;
179
157
$ this ->_request = $ request ;
@@ -185,37 +163,9 @@ public function __construct(
185
163
$ this ->_errorProcessor = $ errorProcessor ;
186
164
$ this ->_pathProcessor = $ pathProcessor ;
187
165
$ this ->areaList = $ areaList ;
188
- $ this ->fieldsFilter = $ fieldsFilter ;
189
166
$ this ->paramsOverrider = $ paramsOverrider ;
190
- $ this ->serviceOutputProcessor = $ serviceOutputProcessor ;
191
- $ this ->swaggerGenerator = $ swaggerGenerator ;
192
167
$ this ->storeManager = $ storeManager ;
193
- }
194
-
195
- /**
196
- * Get deployment config
197
- *
198
- * @return DeploymentConfig
199
- */
200
- private function getDeploymentConfig ()
201
- {
202
- if (!$ this ->deploymentConfig instanceof \Magento \Framework \App \DeploymentConfig) {
203
- $ this ->deploymentConfig = \Magento \Framework \App \ObjectManager::getInstance ()
204
- ->get (\Magento \Framework \App \DeploymentConfig::class);
205
- }
206
- return $ this ->deploymentConfig ;
207
- }
208
-
209
- /**
210
- * Set deployment config
211
- *
212
- * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
213
- * @return void
214
- * @deprecated 100.1.0
215
- */
216
- public function setDeploymentConfig (\Magento \Framework \App \DeploymentConfig $ deploymentConfig )
217
- {
218
- $ this ->deploymentConfig = $ deploymentConfig ;
168
+ $ this ->requestProcessorPool = $ requestProcessorPool ;
219
169
}
220
170
221
171
/**
@@ -234,15 +184,13 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
234
184
$ this ->areaList ->getArea ($ this ->_appState ->getAreaCode ())
235
185
->load (\Magento \Framework \App \Area::PART_TRANSLATE );
236
186
try {
237
- if ($ this ->isSchemaRequest ()) {
238
- $ this ->processSchemaRequest ();
239
- } else {
240
- $ this ->processApiRequest ();
241
- }
187
+ $ processor = $ this ->requestProcessorPool ->getProcessor ($ this ->_request );
188
+ $ processor ->process ($ this ->_request );
242
189
} catch (\Exception $ e ) {
243
190
$ maskedException = $ this ->_errorProcessor ->maskException ($ e );
244
191
$ this ->_response ->setException ($ maskedException );
245
192
}
193
+
246
194
return $ this ->_response ;
247
195
}
248
196
@@ -268,6 +216,7 @@ protected function getCurrentRoute()
268
216
if (!$ this ->_route ) {
269
217
$ this ->_route = $ this ->_router ->match ($ this ->_request );
270
218
}
219
+
271
220
return $ this ->_route ;
272
221
}
273
222
@@ -290,60 +239,6 @@ protected function checkPermissions()
290
239
}
291
240
}
292
241
293
- /**
294
- * Execute schema request
295
- *
296
- * @return void
297
- */
298
- protected function processSchemaRequest ()
299
- {
300
- $ requestedServices = $ this ->_request ->getRequestedServices ('all ' );
301
- $ requestedServices = $ requestedServices == Request::ALL_SERVICES
302
- ? $ this ->swaggerGenerator ->getListOfServices ()
303
- : $ requestedServices ;
304
- $ responseBody = $ this ->swaggerGenerator ->generate (
305
- $ requestedServices ,
306
- $ this ->_request ->getScheme (),
307
- $ this ->_request ->getHttpHost (false ),
308
- $ this ->_request ->getRequestUri ()
309
- );
310
- $ this ->_response ->setBody ($ responseBody )->setHeader ('Content-Type ' , 'application/json ' );
311
- }
312
-
313
- /**
314
- * Execute API request
315
- *
316
- * @return void
317
- * @throws AuthorizationException
318
- * @throws \Magento\Framework\Exception\InputException
319
- * @throws \Magento\Framework\Webapi\Exception
320
- */
321
- protected function processApiRequest ()
322
- {
323
- $ inputParams = $ this ->getInputParamsResolver ()->resolve ();
324
-
325
- $ route = $ this ->getInputParamsResolver ()->getRoute ();
326
- $ serviceMethodName = $ route ->getServiceMethod ();
327
- $ serviceClassName = $ route ->getServiceClass ();
328
-
329
- $ service = $ this ->_objectManager ->get ($ serviceClassName );
330
- /** @var \Magento\Framework\Api\AbstractExtensibleObject $outputData */
331
- $ outputData = call_user_func_array ([$ service , $ serviceMethodName ], $ inputParams );
332
- $ outputData = $ this ->serviceOutputProcessor ->process (
333
- $ outputData ,
334
- $ serviceClassName ,
335
- $ serviceMethodName
336
- );
337
- if ($ this ->_request ->getParam (FieldsFilter::FILTER_PARAMETER ) && is_array ($ outputData )) {
338
- $ outputData = $ this ->fieldsFilter ->filter ($ outputData );
339
- }
340
- $ header = $ this ->getDeploymentConfig ()->get (ConfigOptionsListConstants::CONFIG_PATH_X_FRAME_OPT );
341
- if ($ header ) {
342
- $ this ->_response ->setHeader ('X-Frame-Options ' , $ header );
343
- }
344
- $ this ->_response ->prepareResponse ($ outputData );
345
- }
346
-
347
242
/**
348
243
* Validate request
349
244
*
@@ -365,20 +260,4 @@ protected function validateRequest()
365
260
throw new \Magento \Framework \Webapi \Exception (__ ('Cannot perform GET operation with store code \'all \'' ));
366
261
}
367
262
}
368
-
369
- /**
370
- * The getter function to get InputParamsResolver object
371
- *
372
- * @return \Magento\Webapi\Controller\Rest\InputParamsResolver
373
- *
374
- * @deprecated 100.1.0
375
- */
376
- private function getInputParamsResolver ()
377
- {
378
- if ($ this ->inputParamsResolver === null ) {
379
- $ this ->inputParamsResolver = \Magento \Framework \App \ObjectManager::getInstance ()
380
- ->get (\Magento \Webapi \Controller \Rest \InputParamsResolver::class);
381
- }
382
- return $ this ->inputParamsResolver ;
383
- }
384
263
}
0 commit comments