Cheetah
All Classes Namespaces Files Functions Variables Pages
FacebookResponse.php
Go to the documentation of this file.
1 <?php
24 namespace Facebook;
25 
29 
36 {
40  protected $httpStatusCode;
41 
45  protected $headers;
46 
50  protected $body;
51 
55  protected $decodedBody = [];
56 
60  protected $request;
61 
65  protected $thrownException;
66 
75  public function __construct(FacebookRequest $request, $body = null, $httpStatusCode = null, array $headers = [])
76  {
77  $this->request = $request;
78  $this->body = $body;
79  $this->httpStatusCode = $httpStatusCode;
80  $this->headers = $headers;
81 
82  $this->decodeBody();
83  }
84 
90  public function getRequest()
91  {
92  return $this->request;
93  }
94 
100  public function getApp()
101  {
102  return $this->request->getApp();
103  }
104 
110  public function getAccessToken()
111  {
112  return $this->request->getAccessToken();
113  }
114 
120  public function getHttpStatusCode()
121  {
122  return $this->httpStatusCode;
123  }
124 
130  public function getHeaders()
131  {
132  return $this->headers;
133  }
134 
140  public function getBody()
141  {
142  return $this->body;
143  }
144 
150  public function getDecodedBody()
151  {
152  return $this->decodedBody;
153  }
154 
160  public function getAppSecretProof()
161  {
162  return $this->request->getAppSecretProof();
163  }
164 
170  public function getETag()
171  {
172  return isset($this->headers['ETag']) ? $this->headers['ETag'] : null;
173  }
174 
180  public function getGraphVersion()
181  {
182  return isset($this->headers['Facebook-API-Version']) ? $this->headers['Facebook-API-Version'] : null;
183  }
184 
190  public function isError()
191  {
192  return isset($this->decodedBody['error']);
193  }
194 
200  public function throwException()
201  {
202  throw $this->thrownException;
203  }
204 
208  public function makeException()
209  {
210  $this->thrownException = FacebookResponseException::create($this);
211  }
212 
218  public function getThrownException()
219  {
220  return $this->thrownException;
221  }
222 
234  public function decodeBody()
235  {
236  $this->decodedBody = json_decode($this->body, true);
237 
238  if ($this->decodedBody === null) {
239  $this->decodedBody = [];
240  parse_str($this->body, $this->decodedBody);
241  } elseif (is_bool($this->decodedBody)) {
242  // Backwards compatibility for Graph < 2.1.
243  // Mimics 2.1 responses.
244  // @TODO Remove this after Graph 2.0 is no longer supported
245  $this->decodedBody = ['success' => $this->decodedBody];
246  } elseif (is_numeric($this->decodedBody)) {
247  $this->decodedBody = ['id' => $this->decodedBody];
248  }
249 
250  if (!is_array($this->decodedBody)) {
251  $this->decodedBody = [];
252  }
253 
254  if ($this->isError()) {
255  $this->makeException();
256  }
257  }
258 
271  public function getGraphObject($subclassName = null)
272  {
273  return $this->getGraphNode($subclassName);
274  }
275 
285  public function getGraphNode($subclassName = null)
286  {
287  $factory = new GraphNodeFactory($this);
288 
289  return $factory->makeGraphNode($subclassName);
290  }
291 
299  public function getGraphAlbum()
300  {
301  $factory = new GraphNodeFactory($this);
302 
303  return $factory->makeGraphAlbum();
304  }
305 
313  public function getGraphPage()
314  {
315  $factory = new GraphNodeFactory($this);
316 
317  return $factory->makeGraphPage();
318  }
319 
327  public function getGraphSessionInfo()
328  {
329  $factory = new GraphNodeFactory($this);
330 
331  return $factory->makeGraphSessionInfo();
332  }
333 
341  public function getGraphUser()
342  {
343  $factory = new GraphNodeFactory($this);
344 
345  return $factory->makeGraphUser();
346  }
347 
355  public function getGraphEvent()
356  {
357  $factory = new GraphNodeFactory($this);
358 
359  return $factory->makeGraphEvent();
360  }
361 
369  public function getGraphGroup()
370  {
371  $factory = new GraphNodeFactory($this);
372 
373  return $factory->makeGraphGroup();
374  }
375 
389  public function getGraphList($subclassName = null, $auto_prefix = true)
390  {
391  return $this->getGraphEdge($subclassName, $auto_prefix);
392  }
393 
404  public function getGraphEdge($subclassName = null, $auto_prefix = true)
405  {
406  $factory = new GraphNodeFactory($this);
407 
408  return $factory->makeGraphEdge($subclassName, $auto_prefix);
409  }
410 }
Facebook\FacebookResponse\getGraphVersion
getGraphVersion()
Definition: FacebookResponse.php:180
Facebook\Exceptions\FacebookSDKException
Definition: FacebookSDKException.php:32
Facebook\FacebookResponse\getApp
getApp()
Definition: FacebookResponse.php:100
Facebook\FacebookResponse\$httpStatusCode
$httpStatusCode
Definition: FacebookResponse.php:40
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
Facebook\FacebookResponse\getDecodedBody
getDecodedBody()
Definition: FacebookResponse.php:150
Facebook\FacebookResponse\throwException
throwException()
Definition: FacebookResponse.php:200
php
Facebook\FacebookResponse\getAccessToken
getAccessToken()
Definition: FacebookResponse.php:110
Facebook\FacebookResponse
Definition: FacebookResponse.php:36
Facebook\FacebookResponse\makeException
makeException()
Definition: FacebookResponse.php:208
Facebook\FacebookResponse\$headers
$headers
Definition: FacebookResponse.php:45
Facebook\FacebookResponse\getGraphUser
getGraphUser()
Definition: FacebookResponse.php:341
Facebook\FacebookResponse\getGraphObject
getGraphObject($subclassName=null)
Definition: FacebookResponse.php:271
Facebook\Exceptions\FacebookResponseException
Definition: FacebookResponseException.php:34
Facebook\FacebookResponse\$body
$body
Definition: FacebookResponse.php:50
Facebook\FacebookResponse\__construct
__construct(FacebookRequest $request, $body=null, $httpStatusCode=null, array $headers=[])
Definition: FacebookResponse.php:75
Facebook\FacebookResponse\getETag
getETag()
Definition: FacebookResponse.php:170
Facebook\FacebookResponse\getBody
getBody()
Definition: FacebookResponse.php:140
Facebook\FacebookResponse\getGraphSessionInfo
getGraphSessionInfo()
Definition: FacebookResponse.php:327
Facebook\GraphNodes\GraphNodeFactory
Definition: GraphNodeFactory.php:44
Facebook\FacebookResponse\getGraphNode
getGraphNode($subclassName=null)
Definition: FacebookResponse.php:285
Facebook\FacebookResponse\decodeBody
decodeBody()
Definition: FacebookResponse.php:234
Facebook\FacebookResponse\getGraphEdge
getGraphEdge($subclassName=null, $auto_prefix=true)
Definition: FacebookResponse.php:404
Facebook\FacebookResponse\getHttpStatusCode
getHttpStatusCode()
Definition: FacebookResponse.php:120
Facebook\FacebookResponse\getGraphPage
getGraphPage()
Definition: FacebookResponse.php:313
Facebook\FacebookResponse\getGraphAlbum
getGraphAlbum()
Definition: FacebookResponse.php:299
Facebook
Facebook\FacebookResponse\getGraphEvent
getGraphEvent()
Definition: FacebookResponse.php:355
Facebook\FacebookResponse\getThrownException
getThrownException()
Definition: FacebookResponse.php:218
Facebook\FacebookResponse\$request
$request
Definition: FacebookResponse.php:60
Facebook\FacebookResponse\getRequest
getRequest()
Definition: FacebookResponse.php:90
Facebook\FacebookResponse\getGraphList
getGraphList($subclassName=null, $auto_prefix=true)
Definition: FacebookResponse.php:389
Facebook\FacebookResponse\getHeaders
getHeaders()
Definition: FacebookResponse.php:130
Facebook\FacebookResponse\$thrownException
$thrownException
Definition: FacebookResponse.php:65
Facebook\FacebookResponse\getGraphGroup
getGraphGroup()
Definition: FacebookResponse.php:369
Facebook\FacebookResponse\isError
isError()
Definition: FacebookResponse.php:190
Facebook\FacebookRequest
Definition: FacebookRequest.php:40
Facebook\FacebookResponse\getAppSecretProof
getAppSecretProof()
Definition: FacebookResponse.php:160