本文整理汇总了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;
}
示例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) {
}
}
示例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;
}
示例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());
}
示例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);
}
示例6: send
public function send()
{
if (!$this->client) {
throw new RuntimeException('A client must be set on the request');
}
return $this->client->send($this);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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);
}
}