You are here

protected function Report::getResponse in Acquia Content Hub 8.2

Get Response method.

@todo Copied from preview. Move it a more generic class.

Parameters

\Drupal\acquia_contenthub\Event\HandleWebhookEvent $event: Webhook event.

string $body: Body of response.

Return value

\Psr\Http\Message\ResponseInterface Signed response.

1 call to Report::getResponse()
Report::onHandleWebhook in src/EventSubscriber/HandleWebhook/Report.php
Handles webhook events.

File

src/EventSubscriber/HandleWebhook/Report.php, line 99

Class

Report
Handles webhooks with a payload requesting site report.

Namespace

Drupal\acquia_contenthub\EventSubscriber\HandleWebhook

Code

protected function getResponse(HandleWebhookEvent $event, string $body) : ResponseInterface {
  $response = new GuzzleResponse(Response::HTTP_OK, [], $body);
  if (class_exists(DiactorosFactory::class)) {
    $httpMessageFactory = new DiactorosFactory();
  }
  else {
    $httpMessageFactory = new PsrHttpFactory(new ServerRequestFactory(), new StreamFactory(), new UploadedFileFactory(), new ResponseFactory());
  }
  $psr7_request = $httpMessageFactory
    ->createRequest($event
    ->getRequest());
  $signer = new ResponseSigner($event
    ->getKey(), $psr7_request);
  $signedResponse = $signer
    ->signResponse($response);
  return $signedResponse;
}