Cheetah
GraphRawResponse.php
Go to the documentation of this file.
1 <?php
24 namespace Facebook\Http;
25 
32 {
36  protected $headers;
37 
41  protected $body;
42 
46  protected $httpResponseCode;
47 
55  public function __construct($headers, $body, $httpStatusCode = null)
56  {
57  if (is_numeric($httpStatusCode)) {
58  $this->httpResponseCode = (int)$httpStatusCode;
59  }
60 
61  if (is_array($headers)) {
62  $this->headers = $headers;
63  } else {
65  }
66 
67  $this->body = $body;
68  }
69 
75  public function getHeaders()
76  {
77  return $this->headers;
78  }
79 
85  public function getBody()
86  {
87  return $this->body;
88  }
89 
95  public function getHttpResponseCode()
96  {
98  }
99 
105  public function setHttpResponseCodeFromHeader($rawResponseHeader)
106  {
107  preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match);
108  $this->httpResponseCode = (int)$match[1];
109  }
110 
116  protected function setHeadersFromString($rawHeaders)
117  {
118  // Normalize line breaks
119  $rawHeaders = str_replace("\r\n", "\n", $rawHeaders);
120 
121  // There will be multiple headers if a 301 was followed
122  // or a proxy was followed, etc
123  $headerCollection = explode("\n\n", trim($rawHeaders));
124  // We just want the last response (at the end)
125  $rawHeader = array_pop($headerCollection);
126 
127  $headerComponents = explode("\n", $rawHeader);
128  foreach ($headerComponents as $line) {
129  if (strpos($line, ': ') === false) {
130  $this->setHttpResponseCodeFromHeader($line);
131  } else {
132  list($key, $value) = explode(': ', $line, 2);
133  $this->headers[$key] = $value;
134  }
135  }
136  }
137 }
Facebook\Http\GraphRawResponse\__construct
__construct($headers, $body, $httpStatusCode=null)
Definition: GraphRawResponse.php:55
Facebook\Http\GraphRawResponse\$body
$body
Definition: GraphRawResponse.php:41
Facebook\Http\GraphRawResponse\getHttpResponseCode
getHttpResponseCode()
Definition: GraphRawResponse.php:95
php
Facebook\Http\GraphRawResponse\setHttpResponseCodeFromHeader
setHttpResponseCodeFromHeader($rawResponseHeader)
Definition: GraphRawResponse.php:105
Facebook\Http\GraphRawResponse\setHeadersFromString
setHeadersFromString($rawHeaders)
Definition: GraphRawResponse.php:116
Facebook\Http\GraphRawResponse\getHeaders
getHeaders()
Definition: GraphRawResponse.php:75
Facebook\Http\GraphRawResponse\$httpResponseCode
$httpResponseCode
Definition: GraphRawResponse.php:46
Facebook\Http
Definition: GraphRawResponse.php:24
Facebook\Http\GraphRawResponse\$headers
$headers
Definition: GraphRawResponse.php:36
Facebook\Http\GraphRawResponse\getBody
getBody()
Definition: GraphRawResponse.php:85
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
Facebook\Http\GraphRawResponse
Definition: GraphRawResponse.php:32