Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynchronousRequestProcessor.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
21 {
22  const PROCESSOR_PATH = "/^\\/V\\d+/";
23 
27  private $response;
28 
32  private $inputParamsResolver;
33 
37  private $serviceOutputProcessor;
38 
42  private $fieldsFilter;
43 
47  private $deploymentConfig;
48 
52  private $objectManager;
53 
64  public function __construct(
65  RestResponse $response,
66  InputParamsResolver $inputParamsResolver,
67  ServiceOutputProcessor $serviceOutputProcessor,
68  FieldsFilter $fieldsFilter,
69  DeploymentConfig $deploymentConfig,
70  ObjectManagerInterface $objectManager
71  ) {
72  $this->response = $response;
73  $this->inputParamsResolver = $inputParamsResolver;
74  $this->serviceOutputProcessor = $serviceOutputProcessor;
75  $this->fieldsFilter = $fieldsFilter;
76  $this->deploymentConfig = $deploymentConfig;
77  $this->objectManager = $objectManager;
78  }
79 
83  public function process(\Magento\Framework\Webapi\Rest\Request $request)
84  {
85  $inputParams = $this->inputParamsResolver->resolve();
86 
87  $route = $this->inputParamsResolver->getRoute();
88  $serviceMethodName = $route->getServiceMethod();
89  $serviceClassName = $route->getServiceClass();
90  $service = $this->objectManager->get($serviceClassName);
91 
95  $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams);
96  $outputData = $this->serviceOutputProcessor->process(
97  $outputData,
98  $serviceClassName,
99  $serviceMethodName
100  );
101  if ($request->getParam(FieldsFilter::FILTER_PARAMETER) && is_array($outputData)) {
102  $outputData = $this->fieldsFilter->filter($outputData);
103  }
104  $header = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_X_FRAME_OPT);
105  if ($header) {
106  $this->response->setHeader('X-Frame-Options', $header);
107  }
108  $this->response->prepareResponse($outputData);
109  }
110 
114  public function canProcess(\Magento\Framework\Webapi\Rest\Request $request)
115  {
116  if (preg_match(self::PROCESSOR_PATH, $request->getPathInfo()) === 1) {
117  return true;
118  }
119  return false;
120  }
121 }
$response
Definition: 404.php:11
$objectManager
Definition: bootstrap.php:17
$deploymentConfig
__construct(RestResponse $response, InputParamsResolver $inputParamsResolver, ServiceOutputProcessor $serviceOutputProcessor, FieldsFilter $fieldsFilter, DeploymentConfig $deploymentConfig, ObjectManagerInterface $objectManager)
process(\Magento\Framework\Webapi\Rest\Request $request)
canProcess(\Magento\Framework\Webapi\Rest\Request $request)