Cheetah
FacebookGuzzleHttpClient.php
Go to the documentation of this file.
1 <?php
24 namespace Facebook\HttpClients;
25 
28 
29 use GuzzleHttp\Client;
30 use GuzzleHttp\Message\ResponseInterface;
31 use GuzzleHttp\Ring\Exception\RingException;
32 use GuzzleHttp\Exception\RequestException;
33 
35 {
39  protected $guzzleClient;
40 
44  public function __construct(Client $guzzleClient = null)
45  {
46  $this->guzzleClient = $guzzleClient ?: new Client();
47  }
48 
52  public function send($url, $method, $body, array $headers, $timeOut)
53  {
54  $options = [
55  'headers' => $headers,
56  'body' => $body,
57  'timeout' => $timeOut,
58  'connect_timeout' => 10,
59  'verify' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem',
60  ];
61  $request = $this->guzzleClient->createRequest($method, $url, $options);
62 
63  try {
64  $rawResponse = $this->guzzleClient->send($request);
65  } catch (RequestException $e) {
66  $rawResponse = $e->getResponse();
67 
68  if ($e->getPrevious() instanceof RingException || !$rawResponse instanceof ResponseInterface) {
69  throw new FacebookSDKException($e->getMessage(), $e->getCode());
70  }
71  }
72 
73  $rawHeaders = $this->getHeadersAsString($rawResponse);
74  $rawBody = $rawResponse->getBody();
75  $httpStatusCode = $rawResponse->getStatusCode();
76 
77  return new GraphRawResponse($rawHeaders, $rawBody, $httpStatusCode);
78  }
79 
87  public function getHeadersAsString(ResponseInterface $response)
88  {
89  $headers = $response->getHeaders();
90  $rawHeaders = [];
91  foreach ($headers as $name => $values) {
92  $rawHeaders[] = $name . ": " . implode(", ", $values);
93  }
94 
95  return implode("\r\n", $rawHeaders);
96  }
97 }
Facebook\Exceptions\FacebookSDKException
Definition: FacebookSDKException.php:32
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
php
Facebook\HttpClients\FacebookGuzzleHttpClient\send
send($url, $method, $body, array $headers, $timeOut)
Definition: FacebookGuzzleHttpClient.php:52
Facebook\HttpClients\FacebookGuzzleHttpClient
Definition: FacebookGuzzleHttpClient.php:35
$url
URI MungeSecretKey $url
Definition: URI.MungeSecretKey.txt:14
Facebook\HttpClients\FacebookGuzzleHttpClient\$guzzleClient
$guzzleClient
Definition: FacebookGuzzleHttpClient.php:39
Facebook\HttpClients\FacebookHttpClientInterface
Definition: FacebookHttpClientInterface.php:32
Facebook\HttpClients\FacebookGuzzleHttpClient\getHeadersAsString
getHeadersAsString(ResponseInterface $response)
Definition: FacebookGuzzleHttpClient.php:87
Facebook\HttpClients
Definition: FacebookCurl.php:24
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
Facebook\HttpClients\FacebookGuzzleHttpClient\__construct
__construct(Client $guzzleClient=null)
Definition: FacebookGuzzleHttpClient.php:44
Facebook\Http\GraphRawResponse
Definition: GraphRawResponse.php:32