Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function sendAsyncRequest(RequestInterface $request)
 {
     $pluginChain = $this->createPluginChain($this->plugins, function (RequestInterface $request) {
         return $this->client->sendAsyncRequest($request);
     });
     return $pluginChain($request);
 }
Beispiel #2
0
 /**
  * Send all pending invalidation requests and make sure the requests have terminated and gather exceptions.
  *
  * @return int The number of cache invalidations performed per caching server
  *
  * @throws ExceptionCollection If any errors occurred during flush
  */
 public function flush()
 {
     $queue = $this->queue;
     $this->queue = [];
     /** @var Promise[] $promises */
     $promises = [];
     $exceptions = new ExceptionCollection();
     foreach ($queue as $request) {
         foreach ($this->fanOut($request) as $proxyRequest) {
             $promises[] = $this->httpClient->sendAsyncRequest($proxyRequest);
         }
     }
     if (count($exceptions)) {
         throw new ExceptionCollection($exceptions);
     }
     foreach ($promises as $promise) {
         try {
             $promise->wait();
         } catch (HttpException $exception) {
             $exceptions->add(ProxyResponseException::proxyResponse($exception->getResponse()));
         } catch (RequestException $exception) {
             $exceptions->add(ProxyUnreachableException::proxyUnreachable($exception));
         } catch (\Exception $exception) {
             $exceptions->add(new InvalidArgumentException($exception));
         }
     }
     if (count($exceptions)) {
         throw $exceptions;
     }
     return count($queue);
 }
Beispiel #3
0
 /**
  * Make an asynchronous call to the API
  *
  * @param string $operationId The name of your operation as described in the API Schema
  * @param array $params An array of request parameters
  *
  * @return Promise
  */
 public function callAsync($operationId, array $params = [])
 {
     if (!$this->client instanceof HttpAsyncClient) {
         throw new \RuntimeException(sprintf('"%s" does not support async request', get_class($this->client)));
     }
     $requestDefinition = $this->schema->getRequestDefinition($operationId);
     $request = $this->createRequestFromDefinition($requestDefinition, $params);
     $promise = $this->client->sendAsyncRequest($request);
     return $promise->then(function (ResponseInterface $response) use($request, $requestDefinition) {
         return $this->getDataFromResponse($response, $requestDefinition->getResponseDefinition($response->getStatusCode()), $request);
     });
 }
 /**
  * @dataProvider requestWithOutcomeProvider
  * @group        integration
  */
 public function testSendAsyncRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body)
 {
     if ($protocolVersion === '1.0') {
         $body = null;
     }
     if ($body != null) {
         $headers['Content-Length'] = (string) strlen($body);
     }
     $request = self::$messageFactory->createRequest($method = 'GET', $uriAndOutcome[0], $headers, $body, $protocolVersion);
     $outcome = $uriAndOutcome[1];
     $outcome['protocolVersion'] = $protocolVersion;
     $response = null;
     $promise = $this->httpAsyncClient->sendAsyncRequest($request);
     $promise->then(function ($r) use(&$response) {
         $response = $r;
         return $response;
     });
     $this->assertInstanceOf('Http\\Promise\\Promise', $promise);
     $promise->wait();
     $this->assertResponse($response, $outcome);
     $this->assertRequest($method, $headers, $body, $protocolVersion);
 }
Beispiel #5
0
 /**
  * @param \Psr\Http\Message\RequestInterface $request
  * @return \Http\Promise\Promise
  */
 public function sendAsyncRequest(RequestInterface $request)
 {
     return $this->client->sendAsyncRequest($request);
 }