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


PHP ClientInterface::send方法代码示例

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


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

示例1: load

 /**
  * {@inheritdoc}
  */
 public function load(ClassMetadata $metadata, ParserInterface $parser)
 {
     // Create a request with basic Auth
     $request = $this->client->get('repos/' . $this->owner . '/' . $this->repository . '/contents');
     try {
         // Send the request and get the response.
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         $this->handleBadResponseExceptions($e);
     }
     $files = $response->json();
     $batch = array();
     foreach ($files as $file) {
         $batch[] = $this->client->get('repos/' . $this->owner . '/' . $this->repository . '/contents/' . $file['path']);
     }
     try {
         $responses = $this->client->send($batch);
     } catch (MultiTransferException $e) {
         $this->handleBadResponseExceptions($e->getFirst());
     }
     $content = array();
     foreach ($responses as $response) {
         $file = $response->json();
         $decodedContent = base64_decode($file['content']);
         $content[] = $parser->parse($metadata, $file['name'], $decodedContent);
     }
     return $content;
 }
开发者ID:fabricius,项目名称:fabricius,代码行数:31,代码来源:GithubLoader.php

示例2: doSendInternalRequests

 /**
  * {@inheritdoc}
  */
 protected function doSendInternalRequests(array $internalRequests, $success, $error)
 {
     $requests = array();
     foreach ($internalRequests as $internalRequest) {
         $requests[] = $this->createRequest($internalRequest, $success, $error);
     }
     try {
         $this->client->send($requests);
     } catch (\Exception $e) {
     }
 }
开发者ID:lamenath,项目名称:fbp,代码行数:14,代码来源:GuzzleHttpAdapter.php

示例3: send

 /**
  * Immediately send all queued requests
  *
  * @param bool $async
  * @return $this
  */
 public function send($async = true)
 {
     // Guzzle 3 ignores async; use Guzzle 5 for that.
     try {
         $this->client->send($this->queue);
     } catch (MultiTransferException $exceptions) {
         foreach ($exceptions as $exception) {
             // TODO: handle exceptions gracefully
             throw $exception;
         }
     }
     return $this;
 }
开发者ID:HRcc,项目名称:raven-php,代码行数:19,代码来源:GuzzleTransport.php

示例4: callApi

 public function callApi(ApiCallInterface $apiCall)
 {
     $request = $this->createRequestForApiCall($apiCall);
     try {
         $response = $this->guzzleClient->send($request);
         if (!$response->isSuccessful()) {
             throw new RequestFailedException('Response not successful: ' . (string) $response);
         }
     } catch (RequestException $exception) {
         throw new RequestFailedException('Request failed: ' . $exception->getMessage(), null, $exception);
     }
     return $apiCall->createResponseDto($response->getBody());
 }
开发者ID:matthiasnoback,项目名称:leanpub-api-client,代码行数:13,代码来源:GuzzleClient.php

示例5: download

 public function download()
 {
     $progressFunctions = null;
     if ($this->getProgressFunction()) {
         $progressFunctions = $this->createProgressFunctions(array_fill(0, count($this->requests), 0));
     }
     $requests = array();
     foreach ($this->requests as $i => $r) {
         $requests[] = $request = $this->client->createRequest('GET', $r['url'], array(), null, array('save_to' => $r['file']));
         if ($progressFunctions !== null) {
             // Guzzle progress is too complex for my needs
             $request->getCurlOptions()->add(CURLOPT_NOPROGRESS, false)->add(CURLOPT_PROGRESSFUNCTION, $progressFunctions[$i]);
         }
     }
     $this->client->send($requests);
 }
开发者ID:mhlavac,项目名称:GeonamesBundle,代码行数:16,代码来源:GuzzleDownloadAdapter.php

示例6: send

 public function send()
 {
     if (!$this->client) {
         throw new RuntimeException('A client must be set on the request');
     }
     return $this->client->send($this);
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:7,代码来源:Request.php

示例7: load

 /**
  * {@inheritdoc}
  */
 public function load(ClassMetadata $metadata, ParserInterface $parser)
 {
     // Create a request with basic Auth
     $request = $this->client->get('metadata/dropbox/' . $this->path);
     try {
         // Send the request and get the response.
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         $this->handleBadResponseExceptions($e);
     }
     $responseBody = $response->json();
     $batch = array();
     foreach ($responseBody['contents'] as $file) {
         $batch[] = $this->client->get('https://api-content.dropbox.com/1/files/dropbox' . $file['path']);
     }
     try {
         $responses = $this->client->send($batch);
     } catch (MultiTransferException $e) {
         $this->handleBadResponseExceptions($e->getFirst());
     }
     $content = array();
     foreach ($responses as $response) {
         $url = parse_url($response->getEffectiveUrl());
         $filename = basename($url['path']);
         $receivedContent = $response->getBody(true);
         $content[] = $parser->parse($metadata, $filename, $receivedContent);
     }
     return $content;
 }
开发者ID:fabricius,项目名称:fabricius,代码行数:32,代码来源:DropboxLoader.php

示例8: sendRequests

    /**
     * Sends all requests to each caching proxy server
     *
     * Requests are sent in parallel to minimise impact on performance.
     *
     * @param RequestInterface[] $requests Requests
     *
     * @throws ExceptionCollection
     */
    private function sendRequests(array $requests)
    {
        $allRequests = array();

        foreach ($requests as $request) {
            $headers = $request->getHeaders()->toArray();
            // Force to re-create Host header if empty, as Apache chokes on this. See #128 for discussion.
            if (empty($headers['Host'])) {
                unset( $headers['Host'] );
            }
            foreach ($this->servers as $server) {
                $proxyRequest = $this->client->createRequest(
                    $request->getMethod(),
                    $server . $request->getResource(),
                    $headers
                );
                $allRequests[] = $proxyRequest;
            }
        }

        try {
            $this->client->send($allRequests);
        } catch (GuzzleExceptionCollection $e) {
            $this->handleException($e);
        }
    }
开发者ID:ataxel,项目名称:tp,代码行数:35,代码来源:AbstractProxyClient.php

示例9: load

 /**
  * {@inheritdoc}
  */
 public function load(ClassMetadata $metadata, ParserInterface $parser, $retries = 0)
 {
     try {
         // Send the request and get the response.
         $response = $this->client->get('files/' . $this->folder . '/children')->send();
     } catch (ClientErrorResponseException $e) {
         if ($this->client->getDefaultOption('request.options/headers/Authorization') && $retries < 1) {
             $this->refreshToken();
             $retries++;
             return $this->load($metadata, $parser, $retries);
         }
         $this->handleBadResponseExceptions($e);
     }
     $json = $response->json();
     $files = $json['items'];
     $batch = array();
     foreach ($files as $file) {
         $batch[] = $this->client->get('files/' . $file['id']);
     }
     try {
         $responses = $this->client->send($batch);
     } catch (MultiTransferException $e) {
         $this->handleBadResponseExceptions($e->getFirst());
     }
     $content = array();
     foreach ($responses as $response) {
         $file = $response->json();
         $response = $this->client->get($file['downloadUrl'])->send();
         $downloadedContent = $response->getBody(true);
         $content[] = $parser->parse($metadata, $file['originalFilename'], $downloadedContent);
     }
     return $content;
 }
开发者ID:fabricius,项目名称:fabricius,代码行数:36,代码来源:GoogleDriveLoader.php

示例10: request

 /**
  * {@inheritDoc}
  */
 public function request($path, $body = null, $httpMethod = 'GET', array $options = array())
 {
     $request = $this->createRequest($httpMethod, $path, $body, $options);
     try {
         $response = $this->client->send($request);
     } catch (RequestException $e) {
         throw new \LogicException($e->getMessage(), $e->getCode(), $e);
     }
     return $response;
 }
开发者ID:ferodss,项目名称:salesforce-api,代码行数:13,代码来源:HttpClient.php

示例11: request

 /**
  * {@inheritDoc}
  */
 public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array())
 {
     $request = $this->createRequest($httpMethod, $path, $body, $headers, $options);
     try {
         $response = $this->client->send($request);
     } catch (\LogicException $e) {
         throw new ErrorException($e->getMessage(), $e->getCode(), $e);
     } catch (\RuntimeException $e) {
         throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
     }
     $this->lastRequest = $request;
     $this->lastResponse = $response;
     return $response;
 }
开发者ID:seleznevdev,项目名称:php-trello-api,代码行数:17,代码来源:HttpClient.php

示例12: request

 /**
  * @param string $method
  * @param string $relativeUrl
  * @param array $params
  * @return array
  * @throws Exception\BaseApiErrorResponseException
  * @throws Exception\RuntimeException
  * @throws Exception\RateLimitExceededException
  */
 public function request($method, $relativeUrl, array $params = [])
 {
     if (!$this->token instanceof AccessToken) {
         throw new RuntimeException('Not authorized yet.');
     }
     $request = $this->httpClient->createRequest($method, $relativeUrl, ['Authorization' => "Bearer {$this->token->accessToken}"], null, $params);
     try {
         $response = $this->httpClient->send($request);
         $body = json_decode($response->getBody(), true) or [];
         return $body;
     } catch (BadResponseException $e) {
         $body = json_decode($e->getResponse()->getBody(), true);
         switch ($body['error_description']) {
             case self::ACCESS_TOKEN_EXPIRED_MESSAGE:
                 $this->refresh();
                 return $this->request($method, $relativeUrl, $params);
             case self::RATE_LIMIT_EXCEEDED_MESSAGE:
                 throw new RateLimitExceededException(self::RATE_LIMIT_EXCEEDED_MESSAGE);
             default:
                 throw new BaseApiErrorResponseException($body, $e->getResponse()->getStatusCode());
         }
     }
 }
开发者ID:quartetcom,项目名称:base-api-php-client,代码行数:32,代码来源:Client.php

示例13: sendRequests

 /**
  * Sends all requests to each caching proxy server.
  *
  * Requests are sent in parallel to minimise impact on performance.
  *
  * @param RequestInterface[] $requests Requests
  *
  * @throws ExceptionCollection
  */
 private function sendRequests(array $requests)
 {
     $allRequests = [];
     foreach ($requests as $request) {
         /* @var RequestInterface $request */
         $proxyRequest = $this->client->createRequest($request->getMethod(), $request->getUrl(), $request->getHeaders());
         $allRequests[] = $proxyRequest;
     }
     try {
         $this->client->send($allRequests);
     } catch (MultiTransferException $e) {
         $this->handleException($e);
     }
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:23,代码来源:Symfony.php


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