You are here

public function AcquiaConnectorMiddleware::__invoke in Acquia Connector 8

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

Invoked method that returns a promise.

File

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

Class

AcquiaConnectorMiddleware
Guzzle middleware for the Acquia Connector API.

Namespace

Drupal\acquia_connector_test

Code

public function __invoke() {
  return function ($handler) {
    return function (RequestInterface $request, array $options) use ($handler) {
      $uri = $request
        ->getUri();

      // API requests to NSPI.
      if ($uri
        ->getScheme() . '://' . $uri
        ->getHost() === 'http://mock-spi-server') {
        return $this
          ->createPromise($request);
      }

      // Otherwise, no intervention. We defer to the handler stack.
      return $handler($request, $options);
    };
  };
}