You are here

protected function PreviewEntity::getResponse in Acquia Content Hub 8.2

Handles webhook response.

Parameters

\Drupal\acquia_contenthub\Event\HandleWebhookEvent $event: Handle webhook event.

string $body: Body of request.

Return value

\Psr\Http\Message\ResponseInterface Returns signed response.

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

File

modules/acquia_contenthub_preview/src/EventSubscriber/HandleWebhook/PreviewEntity.php, line 101

Class

PreviewEntity
Previews entities across content as a service sites.

Namespace

Drupal\acquia_contenthub_preview\EventSubscriber\HandleWebhook

Code

protected function getResponse(HandleWebhookEvent $event, string $body) {
  $response = new Response(200, [], $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;
}