You are here

protected function AcquiaConnectorMiddleware::createPromise in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 tests/modules/src/AcquiaConnectorMiddleware.php \Drupal\acquia_connector_test\AcquiaConnectorMiddleware::createPromise()
  2. 3.x tests/modules/src/AcquiaConnectorMiddleware.php \Drupal\acquia_connector_test\AcquiaConnectorMiddleware::createPromise()

Creates a promise for the NSPI request.

Parameters

\Psr\Http\Message\RequestInterface $request: Request interface.

Return value

\GuzzleHttp\Promise\PromiseInterface Promise interface.

Throws

\Exception

1 call to AcquiaConnectorMiddleware::createPromise()
AcquiaConnectorMiddleware::__invoke in tests/modules/src/AcquiaConnectorMiddleware.php
Invoked method that returns a promise.

File

tests/modules/src/AcquiaConnectorMiddleware.php, line 44

Class

AcquiaConnectorMiddleware
Guzzle middleware for the Acquia Connector API.

Namespace

Drupal\acquia_connector_test

Code

protected function createPromise(RequestInterface $request) {
  $nspiController = new NspiController();
  $path = $request
    ->getUri()
    ->getPath();
  switch ($path) {
    case '/agent-api/subscription':
      $response = $nspiController
        ->getSubscription($request);
      $this
        ->updateRequestCount();
      break;
    case '/spi-api/site':
      $response = $nspiController
        ->nspiUpdate($request);
      $this
        ->updateRequestCount();
      break;
    case '/agent-api/subscription/communication':
      $response = $nspiController
        ->getCommunicationSettings($request);
      $this
        ->updateRequestCount();
      break;
    case '/agent-api/subscription/credentials':
      $response = $nspiController
        ->getCredentials($request);
      $this
        ->updateRequestCount();
      break;
    default:

      // @todo fix problem with adding native route matching and parsing.
      if (strstr($path, '/spi_def/get')) {
        $parts = explode('/', $path);
        $response = $nspiController
          ->spiDefinition($request, $parts[3]);
        $this
          ->updateRequestCount();
      }
      else {
        throw new \Exception("Unhandled path {$path}");
      }
  }
  return new FulfilledPromise($response);
}