Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SchemaRequestProcessor.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
19 
20  const PROCESSOR_PATH = 'schema';
21 
25  private $swaggerGenerator;
26 
30  private $response;
31 
38  public function __construct(
39  Generator $swaggerGenerator,
40  RestResponse $response
41  ) {
42  $this->swaggerGenerator = $swaggerGenerator;
43  $this->response = $response;
44  }
45 
49  public function process(\Magento\Framework\Webapi\Rest\Request $request)
50  {
51  $requestedServices = $request->getRequestedServices('all');
52  $requestedServices = $requestedServices == Request::ALL_SERVICES
53  ? $this->swaggerGenerator->getListOfServices()
54  : $requestedServices;
55  $responseBody = $this->swaggerGenerator->generate(
56  $requestedServices,
57  $request->getScheme(),
58  $request->getHttpHost(false),
59  $request->getRequestUri()
60  );
61  $this->response->setBody($responseBody)->setHeader('Content-Type', 'application/json');
62  }
63 
67  public function canProcess(\Magento\Framework\Webapi\Rest\Request $request)
68  {
69  if (strpos(ltrim($request->getPathInfo(), '/'), self::PROCESSOR_PATH) === 0) {
70  return true;
71  }
72  return false;
73  }
74 }
$response
Definition: 404.php:11
canProcess(\Magento\Framework\Webapi\Rest\Request $request)
process(\Magento\Framework\Webapi\Rest\Request $request)
__construct(Generator $swaggerGenerator, RestResponse $response)