You are here

protected function HandleWebhookTrait::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.

int $response_code: The return response code.

\Symfony\Component\HttpFoundation\Response|null $response: SymfonyResponse.

Return value

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

2 calls to HandleWebhookTrait::getResponse()
GetFile::onHandleWebhook in modules/acquia_contenthub_publisher/src/EventSubscriber/HandleWebhook/GetFile.php
Handles webhook events.
ReExport::onHandleWebhook in modules/acquia_contenthub_publisher/src/EventSubscriber/HandleWebhook/ReExport.php
Handles webhook events.

File

modules/acquia_contenthub_publisher/src/EventSubscriber/HandleWebhook/HandleWebhookTrait.php, line 39

Class

HandleWebhookTrait
Trait with helper functions for handle webhook.

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhook

Code

protected function getResponse(HandleWebhookEvent $event, string $body, int $response_code, SymfonyResponse $response = NULL) : ResponseInterface {
  if (class_exists(DiactorosFactory::class)) {
    $http_message_factory = new DiactorosFactory();
  }
  else {
    $http_message_factory = new PsrHttpFactory(new ServerRequestFactory(), new StreamFactory(), new UploadedFileFactory(), new ResponseFactory());
  }
  $psr7_request = $http_message_factory
    ->createRequest($event
    ->getRequest());
  $signer = new ResponseSigner($event
    ->getKey(), $psr7_request);
  if (!$response) {
    $response = new Response($response_code, [], $body);
  }
  else {
    $response = $http_message_factory
      ->createResponse($response);
  }
  return $signer
    ->signResponse($response);
}