当前位置: 首页>>代码示例>>PHP>>正文


PHP ClientInterface::sendAsync方法代码示例

本文整理汇总了PHP中GuzzleHttp\ClientInterface::sendAsync方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::sendAsync方法的具体用法?PHP ClientInterface::sendAsync怎么用?PHP ClientInterface::sendAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\ClientInterface的用法示例。


在下文中一共展示了ClientInterface::sendAsync方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: it_fails_when_try_to_send_requests_in_bath_with_wrong_method

 /** @test */
 public function it_fails_when_try_to_send_requests_in_bath_with_wrong_method()
 {
     $this->expectException(\RuntimeException::class);
     $expectedRequest1 = new Request('GET', 'http://some-absolute/uri1', ['Accept' => ['application/vnd.eventstore.atom+json']]);
     $this->guzzle->sendAsync($expectedRequest1, [])->willReturn(new Response(200, [], '{"some": "data1"}'));
     $this->client->requestsBatch('PUT', ['http://some-absolute/uri1']);
 }
开发者ID:lzakrzewski,项目名称:http-event-store,代码行数:8,代码来源:HttpClientTest.php

示例2: __invoke

 /**
  * @param Psr7Request $request
  * @param Array       $options Http options for the client.
  *
  * @return GuzzleHttp\Promise\PromiseInterface Promise that will be resolved with a
  *                                             Psr\Http\Message\ResponseInterface
  *                                             response object.
  */
 public function __invoke(RequestInterface $request, array $options)
 {
     // Remove options that are not supported.
     foreach (array_keys($options) as $key) {
         if (!isset(self::$validOptions[$key])) {
             unset($options[$key]);
         }
     }
     return $this->client->sendAsync($request, $options);
 }
开发者ID:apropos,项目名称:ebay-sdk-php,代码行数:18,代码来源:HttpHandler.php

示例3: __invoke

 /**
  * @param Psr7Request $request
  * @param array       $options
  *
  * @return Promise\Promise
  */
 public function __invoke(Psr7Request $request, array $options = [])
 {
     $request = $request->withHeader('User-Agent', $request->getHeaderLine('User-Agent') . ' ' . \GuzzleHttp\default_user_agent());
     return $this->client->sendAsync($request, $this->parseOptions($options))->otherwise(static function (\Exception $e) {
         $error = ['exception' => $e, 'connection_error' => $e instanceof ConnectException, 'response' => null];
         if ($e instanceof RequestException && $e->getResponse()) {
             $error['response'] = $e->getResponse();
         }
         return new Promise\RejectedPromise($error);
     });
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:17,代码来源:GuzzleHandler.php

示例4: __construct

 /**
  * @param ClientInterface $client   Client used to send the requests.
  * @param array|\Iterator $requests Requests or functions that return
  *                                  requests to send concurrently.
  * @param array           $config   Associative array of options
  *     - concurrency: (int) Maximum number of requests to send concurrently
  *     - options: Array of request options to apply to each request.
  *     - fulfilled: (callable) Function to invoke when a request completes.
  *     - rejected: (callable) Function to invoke when a request is rejected.
  */
 public function __construct(ClientInterface $client, $requests, array $config = [])
 {
     // Backwards compatibility.
     if (isset($config['pool_size'])) {
         $config['concurrency'] = $config['pool_size'];
     } elseif (!isset($config['concurrency'])) {
         $config['concurrency'] = 25;
     }
     if (isset($config['options'])) {
         $opts = $config['options'];
         unset($config['options']);
     } else {
         $opts = [];
     }
     $iterable = \GuzzleHttp\Promise\iter_for($requests);
     $requests = function () use($iterable, $client, $opts) {
         foreach ($iterable as $key => $rfn) {
             if ($rfn instanceof RequestInterface) {
                 (yield $key => $client->sendAsync($rfn, $opts));
             } elseif (is_callable($rfn)) {
                 (yield $key => $rfn($opts));
             } else {
                 throw new \InvalidArgumentException('Each value yielded by ' . 'the iterator must be a Psr7\\Http\\Message\\RequestInterface ' . 'or a callable that returns a promise that fulfills ' . 'with a Psr7\\Message\\Http\\ResponseInterface object.');
             }
         }
     };
     $this->each = new EachPromise($requests(), $config);
 }
开发者ID:Rayac,项目名称:search,代码行数:38,代码来源:Pool.php

示例5: run

 /**
  * {@inheritdoc}
  *
  * @return PromiseInterface
  */
 public function run(CommandInterface $command, $result = null)
 {
     $key = $command->getRequestMethod() === 'GET' ? 'query' : 'body';
     $options = [$key => []];
     if (!empty($params = $command->getParams())) {
         $options[$key] = array_merge($options[$key], $params);
     }
     if ($config = $this->getConfig()) {
         if (!empty($config->getSteamKey())) {
             $options[$key]['key'] = $config->getSteamKey();
         }
         $this->urlBuilder->setBaseUrl($config->getBaseSteamApiUrl());
     }
     $request = new Request($command->getRequestMethod(), $this->urlBuilder->build($command));
     return $this->client->sendAsync($request, $options);
 }
开发者ID:m1105,项目名称:steam-api-php,代码行数:21,代码来源:GuzzleAsyncRunner.php

示例6: invoke

 /**
  * {@inheritdoc}
  */
 public function invoke($calls)
 {
     try {
         if (!is_array($calls) && $calls instanceof RpcRequestInterface) {
             $transformedCall = $this->transformCall($calls);
             return new JsonRpcResponseCollection($this->client->sendAsync($this->createHttpRequest($transformedCall)), [new RequestTransformation($calls, $transformedCall)]);
         }
         $requests = [];
         $batchRequest = [];
         foreach ($calls as $key => $call) {
             $transformedCall = $this->transformCall($call);
             $requests[spl_object_hash($call)] = new RequestTransformation($call, $transformedCall);
             $batchRequest[] = $transformedCall;
         }
         return new JsonRpcResponseCollection($this->client->sendAsync($this->createHttpRequest($batchRequest)), $requests);
     } catch (GuzzleException $exception) {
         throw new RemoteCallFailedException($exception->getMessage(), 0, $exception);
     }
 }
开发者ID:scaytrase,项目名称:json-rpc-client,代码行数:22,代码来源:JsonRpcClient.php

示例7: sendAsync

 /**
  * Send asynchronous guzzle request
  *
  * @param RequestInterface $request
  * @param \Tebru\Retrofit\Http\Callback $callback
  * @return null
  */
 public function sendAsync(RequestInterface $request, Callback $callback)
 {
     $this->promises[] = $this->client->sendAsync($request)->then(function (ResponseInterface $response) use($callback, $request) {
         if (null !== $this->eventDispatcher) {
             $this->eventDispatcher->dispatch(AfterSendEvent::NAME, new AfterSendEvent($request, $response));
         }
         $callback->onResponse($response);
     }, function (Exception $exception) use($callback, $request) {
         $response = null;
         $context = [];
         if ($exception instanceof \GuzzleHttp\Exception\RequestException) {
             $request = $exception->getRequest();
             $response = $exception->getResponse();
             $context = $exception->getHandlerContext();
         }
         $requestException = new RequestException($exception->getMessage(), $exception->getCode(), $exception->getPrevious(), $request, $response, $context);
         if (null !== $this->eventDispatcher) {
             $this->eventDispatcher->dispatch(ApiExceptionEvent::NAME, new ApiExceptionEvent($requestException, $request));
         }
         $callback->onFailure($requestException);
     });
 }
开发者ID:tebru,项目名称:retrofit-http-clients,代码行数:29,代码来源:GuzzleV6ClientAdapter.php

示例8: getRequestWorkerFn

 private function getRequestWorkerFn()
 {
     while ($request = $this->queue->pop()) {
         try {
             $this->dispatchSending($request);
             $promise = $this->client->sendAsync($request)->then($this->getRequestFulfilledFn($request), $this->getRequestRejectedFn($request));
             (yield $promise);
         } catch (\Exception $e) {
             // Mark the request as complete so we don't get stuck on it.
             $this->queue->complete($request);
             $this->dispatchException($request, $e, null);
             (yield \GuzzleHttp\Promise\rejection_for($e));
         }
     }
 }
开发者ID:LastCallMedia,项目名称:Crawler,代码行数:15,代码来源:Crawler.php

示例9: sendAsyncRequest

 /**
  * {@inheritdoc}
  */
 public function sendAsyncRequest(RequestInterface $request)
 {
     $promise = $this->client->sendAsync($request);
     return new Guzzle6Promise($promise, $request);
 }
开发者ID:jdrieghe,项目名称:guzzle6-adapter,代码行数:8,代码来源:Guzzle6HttpAdapter.php

示例10: sendAsync

 /**
  * Send asynchronous guzzle request
  *
  * @param Request $request
  * @param \Tebru\Retrofit\Http\Callback $callback
  * @return null
  */
 public function sendAsync(Request $request, Callback $callback)
 {
     $this->promises[] = $this->client->sendAsync($request)->then($callback->success(), $callback->failure());
 }
开发者ID:epfremmer,项目名称:retrofit-http-clients,代码行数:11,代码来源:GuzzleV6ClientAdapter.php

示例11: send

 /**
  * @param RequestInterface $request
  * @return PromiseInterface|ResponseInterface
  */
 protected function send(RequestInterface $request)
 {
     return $this->async ? $this->client->sendAsync($request) : $this->client->send($request);
 }
开发者ID:ChristopherMoll,项目名称:mailchimp-php,代码行数:8,代码来源:BaseManager.php

示例12: sendAsync

 /**
  * {@inheritdoc}
  */
 public function sendAsync(RequestInterface $request, array $options = []) : Promise
 {
     $promise = $this->client->sendAsync($request, $options);
     return new GuzzlePromise($promise, $request);
 }
开发者ID:novuso,项目名称:common-bundle,代码行数:8,代码来源:GuzzleClient.php

示例13: sendAllAsync

 /**
  * {@inheritdoc}
  */
 public function sendAllAsync(array $requests)
 {
     return $this->httpClient->sendAsync($this->createRequest(RequestInterface::BATCH, $this->getBatchRequestOptions($requests)))->then(function (ResponseInterface $response) {
         return $this->getBatchResponses($response);
     });
 }
开发者ID:yashb,项目名称:generator,代码行数:9,代码来源:Client.php


注:本文中的GuzzleHttp\ClientInterface::sendAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。