Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AsynchronousSchemaRequestProcessor.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
15 
17 {
21  const PROCESSOR_PATH = 'async/schema';
22  const BULK_PROCESSOR_PATH = 'async/bulk/schema';
23 
27  private $swaggerGenerator;
31  private $response;
35  private $processorPath;
36 
44  public function __construct(
45  Generator $swaggerGenerator,
46  RestResponse $response,
47  $processorPath = self::PROCESSOR_PATH
48  ) {
49  $this->swaggerGenerator = $swaggerGenerator;
50  $this->response = $response;
51  $this->processorPath = $processorPath;
52  }
53 
57  public function process(\Magento\Framework\Webapi\Rest\Request $request)
58  {
59  $requestedServices = $request->getRequestedServices('all');
60  $requestedServices = $requestedServices == Request::ALL_SERVICES
61  ? $this->swaggerGenerator->getListOfServices()
62  : $requestedServices;
63  $responseBody = $this->swaggerGenerator->generate(
64  $requestedServices,
65  $request->getScheme(),
66  $request->getHttpHost(),
67  $request->getRequestUri()
68  );
69  $this->response->setBody($responseBody)->setHeader('Content-Type', 'application/json');
70  }
71 
75  public function canProcess(\Magento\Framework\Webapi\Rest\Request $request)
76  {
77  if (strpos(ltrim($request->getPathInfo(), '/'), $this->processorPath) === 0) {
78  return true;
79  }
80  return false;
81  }
82 
87  public function isBulk(\Magento\Framework\Webapi\Rest\Request $request)
88  {
89  if (strpos(ltrim($request->getPathInfo(), '/'), self::BULK_PROCESSOR_PATH) === 0) {
90  return true;
91  }
92  return false;
93  }
94 }
$response
Definition: 404.php:11
__construct(Generator $swaggerGenerator, RestResponse $response, $processorPath=self::PROCESSOR_PATH)