@@ -32,122 +32,122 @@ discard block |
||
32 | 32 | class FacebookCurlHttpClient implements FacebookHttpable |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var array The headers to be sent with the request |
|
37 | - */ |
|
38 | - protected $requestHeaders = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * @var array The headers received from the response |
|
42 | - */ |
|
43 | - protected $responseHeaders = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * @var int The HTTP status code returned from the server |
|
47 | - */ |
|
48 | - protected $responseHttpStatusCode = 0; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string The client error message |
|
52 | - */ |
|
53 | - protected $curlErrorMessage = ''; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var int The curl client error code |
|
57 | - */ |
|
58 | - protected $curlErrorCode = 0; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var string|boolean The raw response from the server |
|
62 | - */ |
|
63 | - protected $rawResponse; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var FacebookCurl Procedural curl as object |
|
67 | - */ |
|
68 | - protected static $facebookCurl; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var boolean If IPv6 should be disabled |
|
72 | - */ |
|
73 | - protected static $disableIPv6; |
|
74 | - |
|
75 | - /** |
|
76 | - * @const Curl Version which is unaffected by the proxy header length error. |
|
77 | - */ |
|
78 | - const CURL_PROXY_QUIRK_VER = 0x071E00; |
|
79 | - |
|
80 | - /** |
|
81 | - * @const "Connection Established" header text |
|
82 | - */ |
|
83 | - const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n"; |
|
84 | - |
|
85 | - /** |
|
86 | - * @param FacebookCurl|null Procedural curl as object |
|
87 | - */ |
|
88 | - public function __construct(FacebookCurl $facebookCurl = null) |
|
89 | - { |
|
35 | + /** |
|
36 | + * @var array The headers to be sent with the request |
|
37 | + */ |
|
38 | + protected $requestHeaders = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * @var array The headers received from the response |
|
42 | + */ |
|
43 | + protected $responseHeaders = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * @var int The HTTP status code returned from the server |
|
47 | + */ |
|
48 | + protected $responseHttpStatusCode = 0; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string The client error message |
|
52 | + */ |
|
53 | + protected $curlErrorMessage = ''; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var int The curl client error code |
|
57 | + */ |
|
58 | + protected $curlErrorCode = 0; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var string|boolean The raw response from the server |
|
62 | + */ |
|
63 | + protected $rawResponse; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var FacebookCurl Procedural curl as object |
|
67 | + */ |
|
68 | + protected static $facebookCurl; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var boolean If IPv6 should be disabled |
|
72 | + */ |
|
73 | + protected static $disableIPv6; |
|
74 | + |
|
75 | + /** |
|
76 | + * @const Curl Version which is unaffected by the proxy header length error. |
|
77 | + */ |
|
78 | + const CURL_PROXY_QUIRK_VER = 0x071E00; |
|
79 | + |
|
80 | + /** |
|
81 | + * @const "Connection Established" header text |
|
82 | + */ |
|
83 | + const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n"; |
|
84 | + |
|
85 | + /** |
|
86 | + * @param FacebookCurl|null Procedural curl as object |
|
87 | + */ |
|
88 | + public function __construct(FacebookCurl $facebookCurl = null) |
|
89 | + { |
|
90 | 90 | self::$facebookCurl = $facebookCurl ?: new FacebookCurl(); |
91 | 91 | self::$disableIPv6 = self::$disableIPv6 ?: false; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Disable IPv6 resolution |
|
96 | - */ |
|
97 | - public function disableIPv6() |
|
98 | - { |
|
94 | + /** |
|
95 | + * Disable IPv6 resolution |
|
96 | + */ |
|
97 | + public function disableIPv6() |
|
98 | + { |
|
99 | 99 | self::$disableIPv6 = true; |
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * The headers we want to send with the request |
|
104 | - * |
|
105 | - * @param string $key |
|
106 | - * @param string $value |
|
107 | - */ |
|
108 | - public function addRequestHeader($key, $value) |
|
109 | - { |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * The headers we want to send with the request |
|
104 | + * |
|
105 | + * @param string $key |
|
106 | + * @param string $value |
|
107 | + */ |
|
108 | + public function addRequestHeader($key, $value) |
|
109 | + { |
|
110 | 110 | $this->requestHeaders[$key] = $value; |
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * The headers returned in the response |
|
115 | - * |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - public function getResponseHeaders() |
|
119 | - { |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * The headers returned in the response |
|
115 | + * |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + public function getResponseHeaders() |
|
119 | + { |
|
120 | 120 | return $this->responseHeaders; |
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * The HTTP status response code |
|
125 | - * |
|
126 | - * @return int |
|
127 | - */ |
|
128 | - public function getResponseHttpStatusCode() |
|
129 | - { |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * The HTTP status response code |
|
125 | + * |
|
126 | + * @return int |
|
127 | + */ |
|
128 | + public function getResponseHttpStatusCode() |
|
129 | + { |
|
130 | 130 | return $this->responseHttpStatusCode; |
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Sends a request to the server |
|
135 | - * |
|
136 | - * @param string $url The endpoint to send the request to |
|
137 | - * @param string $method The request method |
|
138 | - * @param array $parameters The key value pairs to be sent in the body |
|
139 | - * |
|
140 | - * @return string Raw response from the server |
|
141 | - * |
|
142 | - * @throws \Facebook\FacebookSDKException |
|
143 | - */ |
|
144 | - public function send($url, $method = 'GET', $parameters = array()) |
|
145 | - { |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Sends a request to the server |
|
135 | + * |
|
136 | + * @param string $url The endpoint to send the request to |
|
137 | + * @param string $method The request method |
|
138 | + * @param array $parameters The key value pairs to be sent in the body |
|
139 | + * |
|
140 | + * @return string Raw response from the server |
|
141 | + * |
|
142 | + * @throws \Facebook\FacebookSDKException |
|
143 | + */ |
|
144 | + public function send($url, $method = 'GET', $parameters = array()) |
|
145 | + { |
|
146 | 146 | $this->openConnection($url, $method, $parameters); |
147 | 147 | $this->tryToSendRequest(); |
148 | 148 | |
149 | 149 | if ($this->curlErrorCode) { |
150 | - throw new FacebookSDKException($this->curlErrorMessage, $this->curlErrorCode); |
|
150 | + throw new FacebookSDKException($this->curlErrorMessage, $this->curlErrorCode); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Separate the raw headers from the raw body |
@@ -158,114 +158,114 @@ discard block |
||
158 | 158 | $this->closeConnection(); |
159 | 159 | |
160 | 160 | return $rawBody; |
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Opens a new curl connection |
|
165 | - * |
|
166 | - * @param string $url The endpoint to send the request to |
|
167 | - * @param string $method The request method |
|
168 | - * @param array $parameters The key value pairs to be sent in the body |
|
169 | - */ |
|
170 | - public function openConnection($url, $method = 'GET', $parameters = array()) |
|
171 | - { |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Opens a new curl connection |
|
165 | + * |
|
166 | + * @param string $url The endpoint to send the request to |
|
167 | + * @param string $method The request method |
|
168 | + * @param array $parameters The key value pairs to be sent in the body |
|
169 | + */ |
|
170 | + public function openConnection($url, $method = 'GET', $parameters = array()) |
|
171 | + { |
|
172 | 172 | $options = array( |
173 | - CURLOPT_URL => $url, |
|
174 | - CURLOPT_CONNECTTIMEOUT => 10, |
|
175 | - CURLOPT_TIMEOUT => 60, |
|
176 | - CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects |
|
177 | - CURLOPT_HEADER => true, // Enable header processing |
|
178 | - CURLOPT_SSL_VERIFYHOST => 2, |
|
179 | - CURLOPT_SSL_VERIFYPEER => true, |
|
180 | - CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
173 | + CURLOPT_URL => $url, |
|
174 | + CURLOPT_CONNECTTIMEOUT => 10, |
|
175 | + CURLOPT_TIMEOUT => 60, |
|
176 | + CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects |
|
177 | + CURLOPT_HEADER => true, // Enable header processing |
|
178 | + CURLOPT_SSL_VERIFYHOST => 2, |
|
179 | + CURLOPT_SSL_VERIFYPEER => true, |
|
180 | + CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
181 | 181 | ); |
182 | 182 | |
183 | 183 | if ($method !== "GET") { |
184 | - $options[CURLOPT_POSTFIELDS] = $parameters; |
|
184 | + $options[CURLOPT_POSTFIELDS] = $parameters; |
|
185 | 185 | } |
186 | 186 | if ($method === 'DELETE' || $method === 'PUT') { |
187 | - $options[CURLOPT_CUSTOMREQUEST] = $method; |
|
187 | + $options[CURLOPT_CUSTOMREQUEST] = $method; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | if (!empty($this->requestHeaders)) { |
191 | - $options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders(); |
|
191 | + $options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders(); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | if (self::$disableIPv6) { |
195 | - $options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; |
|
195 | + $options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | self::$facebookCurl->init(); |
199 | 199 | self::$facebookCurl->setopt_array($options); |
200 | - } |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Closes an existing curl connection |
|
204 | - */ |
|
205 | - public function closeConnection() |
|
206 | - { |
|
202 | + /** |
|
203 | + * Closes an existing curl connection |
|
204 | + */ |
|
205 | + public function closeConnection() |
|
206 | + { |
|
207 | 207 | self::$facebookCurl->close(); |
208 | - } |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * Try to send the request |
|
212 | - */ |
|
213 | - public function tryToSendRequest() |
|
214 | - { |
|
210 | + /** |
|
211 | + * Try to send the request |
|
212 | + */ |
|
213 | + public function tryToSendRequest() |
|
214 | + { |
|
215 | 215 | $this->sendRequest(); |
216 | 216 | $this->curlErrorMessage = self::$facebookCurl->error(); |
217 | 217 | $this->curlErrorCode = self::$facebookCurl->errno(); |
218 | 218 | $this->responseHttpStatusCode = self::$facebookCurl->getinfo(CURLINFO_HTTP_CODE); |
219 | - } |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * Send the request and get the raw response from curl |
|
223 | - */ |
|
224 | - public function sendRequest() |
|
225 | - { |
|
221 | + /** |
|
222 | + * Send the request and get the raw response from curl |
|
223 | + */ |
|
224 | + public function sendRequest() |
|
225 | + { |
|
226 | 226 | $this->rawResponse = self::$facebookCurl->exec(); |
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Compiles the request headers into a curl-friendly format |
|
231 | - * |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - public function compileRequestHeaders() |
|
235 | - { |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Compiles the request headers into a curl-friendly format |
|
231 | + * |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + public function compileRequestHeaders() |
|
235 | + { |
|
236 | 236 | $return = array(); |
237 | 237 | |
238 | 238 | foreach ($this->requestHeaders as $key => $value) { |
239 | - $return[] = $key . ': ' . $value; |
|
239 | + $return[] = $key . ': ' . $value; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | return $return; |
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Extracts the headers and the body into a two-part array |
|
247 | - * |
|
248 | - * @return array |
|
249 | - */ |
|
250 | - public function extractResponseHeadersAndBody() |
|
251 | - { |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Extracts the headers and the body into a two-part array |
|
247 | + * |
|
248 | + * @return array |
|
249 | + */ |
|
250 | + public function extractResponseHeadersAndBody() |
|
251 | + { |
|
252 | 252 | $headerSize = self::getHeaderSize(); |
253 | 253 | |
254 | 254 | $rawHeaders = mb_substr($this->rawResponse, 0, $headerSize); |
255 | 255 | $rawBody = mb_substr($this->rawResponse, $headerSize); |
256 | 256 | |
257 | 257 | return array(trim($rawHeaders), trim($rawBody)); |
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Converts raw header responses into an array |
|
262 | - * |
|
263 | - * @param string $rawHeaders |
|
264 | - * |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - public static function headersToArray($rawHeaders) |
|
268 | - { |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Converts raw header responses into an array |
|
262 | + * |
|
263 | + * @param string $rawHeaders |
|
264 | + * |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + public static function headersToArray($rawHeaders) |
|
268 | + { |
|
269 | 269 | $headers = array(); |
270 | 270 | |
271 | 271 | // Normalize line breaks |
@@ -279,51 +279,51 @@ discard block |
||
279 | 279 | |
280 | 280 | $headerComponents = explode("\n", $rawHeader); |
281 | 281 | foreach ($headerComponents as $line) { |
282 | - if (strpos($line, ': ') === false) { |
|
282 | + if (strpos($line, ': ') === false) { |
|
283 | 283 | $headers['http_code'] = $line; |
284 | - } else { |
|
284 | + } else { |
|
285 | 285 | list ($key, $value) = explode(': ', $line); |
286 | 286 | $headers[$key] = $value; |
287 | - } |
|
287 | + } |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | return $headers; |
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Return proper header size |
|
295 | - * |
|
296 | - * @return integer |
|
297 | - */ |
|
298 | - private function getHeaderSize() |
|
299 | - { |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Return proper header size |
|
295 | + * |
|
296 | + * @return integer |
|
297 | + */ |
|
298 | + private function getHeaderSize() |
|
299 | + { |
|
300 | 300 | $headerSize = self::$facebookCurl->getinfo(CURLINFO_HEADER_SIZE); |
301 | 301 | // This corrects a Curl bug where header size does not account |
302 | 302 | // for additional Proxy headers. |
303 | 303 | if ( self::needsCurlProxyFix() ) { |
304 | - // Additional way to calculate the request body size. |
|
305 | - if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { |
|
306 | - $headerSize = mb_strlen($this->rawResponse) - $m[1]; |
|
307 | - } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { |
|
308 | - $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); |
|
309 | - } |
|
304 | + // Additional way to calculate the request body size. |
|
305 | + if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { |
|
306 | + $headerSize = mb_strlen($this->rawResponse) - $m[1]; |
|
307 | + } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { |
|
308 | + $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); |
|
309 | + } |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | return $headerSize; |
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Detect versions of Curl which report incorrect header lengths when |
|
317 | - * using Proxies. |
|
318 | - * |
|
319 | - * @return boolean |
|
320 | - */ |
|
321 | - private static function needsCurlProxyFix() |
|
322 | - { |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Detect versions of Curl which report incorrect header lengths when |
|
317 | + * using Proxies. |
|
318 | + * |
|
319 | + * @return boolean |
|
320 | + */ |
|
321 | + private static function needsCurlProxyFix() |
|
322 | + { |
|
323 | 323 | $ver = self::$facebookCurl->version(); |
324 | 324 | $version = $ver['version_number']; |
325 | 325 | |
326 | 326 | return $version < self::CURL_PROXY_QUIRK_VER; |
327 | - } |
|
327 | + } |
|
328 | 328 | |
329 | 329 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | CURLOPT_HEADER => true, // Enable header processing |
178 | 178 | CURLOPT_SSL_VERIFYHOST => 2, |
179 | 179 | CURLOPT_SSL_VERIFYPEER => true, |
180 | - CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
180 | + CURLOPT_CAINFO => __DIR__.'/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
181 | 181 | ); |
182 | 182 | |
183 | 183 | if ($method !== "GET") { |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | $return = array(); |
237 | 237 | |
238 | 238 | foreach ($this->requestHeaders as $key => $value) { |
239 | - $return[] = $key . ': ' . $value; |
|
239 | + $return[] = $key.': '.$value; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | return $return; |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | $headerSize = self::$facebookCurl->getinfo(CURLINFO_HEADER_SIZE); |
301 | 301 | // This corrects a Curl bug where header size does not account |
302 | 302 | // for additional Proxy headers. |
303 | - if ( self::needsCurlProxyFix() ) { |
|
303 | + if (self::needsCurlProxyFix()) { |
|
304 | 304 | // Additional way to calculate the request body size. |
305 | 305 | if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { |
306 | 306 | $headerSize = mb_strlen($this->rawResponse) - $m[1]; |
@@ -31,81 +31,81 @@ discard block |
||
31 | 31 | |
32 | 32 | class FacebookGuzzleHttpClient implements FacebookHttpable { |
33 | 33 | |
34 | - /** |
|
35 | - * @var array The headers to be sent with the request |
|
36 | - */ |
|
37 | - protected $requestHeaders = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @var array The headers received from the response |
|
41 | - */ |
|
42 | - protected $responseHeaders = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var int The HTTP status code returned from the server |
|
46 | - */ |
|
47 | - protected $responseHttpStatusCode = 0; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var \GuzzleHttp\Client The Guzzle client |
|
51 | - */ |
|
52 | - protected static $guzzleClient; |
|
53 | - |
|
54 | - /** |
|
55 | - * @param \GuzzleHttp\Client|null The Guzzle client |
|
56 | - */ |
|
57 | - public function __construct(Client $guzzleClient = null) |
|
58 | - { |
|
34 | + /** |
|
35 | + * @var array The headers to be sent with the request |
|
36 | + */ |
|
37 | + protected $requestHeaders = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @var array The headers received from the response |
|
41 | + */ |
|
42 | + protected $responseHeaders = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var int The HTTP status code returned from the server |
|
46 | + */ |
|
47 | + protected $responseHttpStatusCode = 0; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var \GuzzleHttp\Client The Guzzle client |
|
51 | + */ |
|
52 | + protected static $guzzleClient; |
|
53 | + |
|
54 | + /** |
|
55 | + * @param \GuzzleHttp\Client|null The Guzzle client |
|
56 | + */ |
|
57 | + public function __construct(Client $guzzleClient = null) |
|
58 | + { |
|
59 | 59 | self::$guzzleClient = $guzzleClient ?: new Client(); |
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * The headers we want to send with the request |
|
64 | - * |
|
65 | - * @param string $key |
|
66 | - * @param string $value |
|
67 | - */ |
|
68 | - public function addRequestHeader($key, $value) |
|
69 | - { |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * The headers we want to send with the request |
|
64 | + * |
|
65 | + * @param string $key |
|
66 | + * @param string $value |
|
67 | + */ |
|
68 | + public function addRequestHeader($key, $value) |
|
69 | + { |
|
70 | 70 | $this->requestHeaders[$key] = $value; |
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * The headers returned in the response |
|
75 | - * |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function getResponseHeaders() |
|
79 | - { |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * The headers returned in the response |
|
75 | + * |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function getResponseHeaders() |
|
79 | + { |
|
80 | 80 | return $this->responseHeaders; |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * The HTTP status response code |
|
85 | - * |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public function getResponseHttpStatusCode() |
|
89 | - { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * The HTTP status response code |
|
85 | + * |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public function getResponseHttpStatusCode() |
|
89 | + { |
|
90 | 90 | return $this->responseHttpStatusCode; |
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Sends a request to the server |
|
95 | - * |
|
96 | - * @param string $url The endpoint to send the request to |
|
97 | - * @param string $method The request method |
|
98 | - * @param array $parameters The key value pairs to be sent in the body |
|
99 | - * |
|
100 | - * @return string Raw response from the server |
|
101 | - * |
|
102 | - * @throws \Facebook\FacebookSDKException |
|
103 | - */ |
|
104 | - public function send($url, $method = 'GET', $parameters = array()) |
|
105 | - { |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Sends a request to the server |
|
95 | + * |
|
96 | + * @param string $url The endpoint to send the request to |
|
97 | + * @param string $method The request method |
|
98 | + * @param array $parameters The key value pairs to be sent in the body |
|
99 | + * |
|
100 | + * @return string Raw response from the server |
|
101 | + * |
|
102 | + * @throws \Facebook\FacebookSDKException |
|
103 | + */ |
|
104 | + public function send($url, $method = 'GET', $parameters = array()) |
|
105 | + { |
|
106 | 106 | $options = array(); |
107 | 107 | if ($parameters) { |
108 | - $options = array('body' => $parameters); |
|
108 | + $options = array('body' => $parameters); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $options['verify'] = __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem'; |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | $request = self::$guzzleClient->createRequest($method, $url, $options); |
114 | 114 | |
115 | 115 | foreach($this->requestHeaders as $k => $v) { |
116 | - $request->setHeader($k, $v); |
|
116 | + $request->setHeader($k, $v); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | try { |
120 | - $rawResponse = self::$guzzleClient->send($request); |
|
120 | + $rawResponse = self::$guzzleClient->send($request); |
|
121 | 121 | } catch (RequestException $e) { |
122 | - if ($e->getPrevious() instanceof AdapterException) { |
|
122 | + if ($e->getPrevious() instanceof AdapterException) { |
|
123 | 123 | throw new FacebookSDKException($e->getMessage(), $e->getCode()); |
124 | - } |
|
125 | - $rawResponse = $e->getResponse(); |
|
124 | + } |
|
125 | + $rawResponse = $e->getResponse(); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | $this->responseHttpStatusCode = $rawResponse->getStatusCode(); |
129 | 129 | $this->responseHeaders = $rawResponse->getHeaders(); |
130 | 130 | |
131 | 131 | return $rawResponse->getBody(); |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | 134 | } |
@@ -108,11 +108,11 @@ |
||
108 | 108 | $options = array('body' => $parameters); |
109 | 109 | } |
110 | 110 | |
111 | - $options['verify'] = __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem'; |
|
111 | + $options['verify'] = __DIR__.'/certs/DigiCertHighAssuranceEVRootCA.pem'; |
|
112 | 112 | |
113 | 113 | $request = self::$guzzleClient->createRequest($method, $url, $options); |
114 | 114 | |
115 | - foreach($this->requestHeaders as $k => $v) { |
|
115 | + foreach ($this->requestHeaders as $k => $v) { |
|
116 | 116 | $request->setHeader($k, $v); |
117 | 117 | } |
118 | 118 |
@@ -27,96 +27,96 @@ discard block |
||
27 | 27 | |
28 | 28 | class FacebookStreamHttpClient implements FacebookHttpable { |
29 | 29 | |
30 | - /** |
|
31 | - * @var array The headers to be sent with the request |
|
32 | - */ |
|
33 | - protected $requestHeaders = array(); |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array The headers received from the response |
|
37 | - */ |
|
38 | - protected $responseHeaders = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * @var int The HTTP status code returned from the server |
|
42 | - */ |
|
43 | - protected $responseHttpStatusCode = 0; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var FacebookStream Procedural stream wrapper as object |
|
47 | - */ |
|
48 | - protected static $facebookStream; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param FacebookStream|null Procedural stream wrapper as object |
|
52 | - */ |
|
53 | - public function __construct(FacebookStream $facebookStream = null) |
|
54 | - { |
|
30 | + /** |
|
31 | + * @var array The headers to be sent with the request |
|
32 | + */ |
|
33 | + protected $requestHeaders = array(); |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array The headers received from the response |
|
37 | + */ |
|
38 | + protected $responseHeaders = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * @var int The HTTP status code returned from the server |
|
42 | + */ |
|
43 | + protected $responseHttpStatusCode = 0; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var FacebookStream Procedural stream wrapper as object |
|
47 | + */ |
|
48 | + protected static $facebookStream; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param FacebookStream|null Procedural stream wrapper as object |
|
52 | + */ |
|
53 | + public function __construct(FacebookStream $facebookStream = null) |
|
54 | + { |
|
55 | 55 | self::$facebookStream = $facebookStream ?: new FacebookStream(); |
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * The headers we want to send with the request |
|
60 | - * |
|
61 | - * @param string $key |
|
62 | - * @param string $value |
|
63 | - */ |
|
64 | - public function addRequestHeader($key, $value) |
|
65 | - { |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * The headers we want to send with the request |
|
60 | + * |
|
61 | + * @param string $key |
|
62 | + * @param string $value |
|
63 | + */ |
|
64 | + public function addRequestHeader($key, $value) |
|
65 | + { |
|
66 | 66 | $this->requestHeaders[$key] = $value; |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * The headers returned in the response |
|
71 | - * |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getResponseHeaders() |
|
75 | - { |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * The headers returned in the response |
|
71 | + * |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getResponseHeaders() |
|
75 | + { |
|
76 | 76 | return $this->responseHeaders; |
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * The HTTP status response code |
|
81 | - * |
|
82 | - * @return int |
|
83 | - */ |
|
84 | - public function getResponseHttpStatusCode() |
|
85 | - { |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * The HTTP status response code |
|
81 | + * |
|
82 | + * @return int |
|
83 | + */ |
|
84 | + public function getResponseHttpStatusCode() |
|
85 | + { |
|
86 | 86 | return $this->responseHttpStatusCode; |
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Sends a request to the server |
|
91 | - * |
|
92 | - * @param string $url The endpoint to send the request to |
|
93 | - * @param string $method The request method |
|
94 | - * @param array $parameters The key value pairs to be sent in the body |
|
95 | - * |
|
96 | - * @return string Raw response from the server |
|
97 | - * |
|
98 | - * @throws \Facebook\FacebookSDKException |
|
99 | - */ |
|
100 | - public function send($url, $method = 'GET', $parameters = array()) |
|
101 | - { |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Sends a request to the server |
|
91 | + * |
|
92 | + * @param string $url The endpoint to send the request to |
|
93 | + * @param string $method The request method |
|
94 | + * @param array $parameters The key value pairs to be sent in the body |
|
95 | + * |
|
96 | + * @return string Raw response from the server |
|
97 | + * |
|
98 | + * @throws \Facebook\FacebookSDKException |
|
99 | + */ |
|
100 | + public function send($url, $method = 'GET', $parameters = array()) |
|
101 | + { |
|
102 | 102 | $options = array( |
103 | - 'http' => array( |
|
103 | + 'http' => array( |
|
104 | 104 | 'method' => $method, |
105 | 105 | 'timeout' => 60, |
106 | 106 | 'ignore_errors' => true |
107 | - ), |
|
108 | - 'ssl' => array( |
|
107 | + ), |
|
108 | + 'ssl' => array( |
|
109 | 109 | 'verify_peer' => true, |
110 | 110 | 'verify_peer_name' => true, |
111 | 111 | 'allow_self_signed' => true, // All root certificates are self-signed |
112 | 112 | 'cafile' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
113 | - ), |
|
113 | + ), |
|
114 | 114 | ); |
115 | 115 | |
116 | 116 | if ($parameters) { |
117 | - $options['http']['content'] = http_build_query($parameters, null, '&'); |
|
117 | + $options['http']['content'] = http_build_query($parameters, null, '&'); |
|
118 | 118 | |
119 | - $this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded'); |
|
119 | + $this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $options['http']['header'] = $this->compileHeader(); |
@@ -126,65 +126,65 @@ discard block |
||
126 | 126 | $rawHeaders = self::$facebookStream->getResponseHeaders(); |
127 | 127 | |
128 | 128 | if ($rawResponse === false || !$rawHeaders) { |
129 | - throw new FacebookSDKException('Stream returned an empty response', 660); |
|
129 | + throw new FacebookSDKException('Stream returned an empty response', 660); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $this->responseHeaders = self::formatHeadersToArray($rawHeaders); |
133 | 133 | $this->responseHttpStatusCode = self::getStatusCodeFromHeader($this->responseHeaders['http_code']); |
134 | 134 | |
135 | 135 | return $rawResponse; |
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Formats the headers for use in the stream wrapper |
|
140 | - * |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function compileHeader() |
|
144 | - { |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Formats the headers for use in the stream wrapper |
|
140 | + * |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function compileHeader() |
|
144 | + { |
|
145 | 145 | $header = []; |
146 | 146 | foreach($this->requestHeaders as $k => $v) { |
147 | - $header[] = $k . ': ' . $v; |
|
147 | + $header[] = $k . ': ' . $v; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | return implode("\r\n", $header); |
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Converts array of headers returned from the wrapper into |
|
155 | - * something standard |
|
156 | - * |
|
157 | - * @param array $rawHeaders |
|
158 | - * |
|
159 | - * @return array |
|
160 | - */ |
|
161 | - public static function formatHeadersToArray(array $rawHeaders) |
|
162 | - { |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Converts array of headers returned from the wrapper into |
|
155 | + * something standard |
|
156 | + * |
|
157 | + * @param array $rawHeaders |
|
158 | + * |
|
159 | + * @return array |
|
160 | + */ |
|
161 | + public static function formatHeadersToArray(array $rawHeaders) |
|
162 | + { |
|
163 | 163 | $headers = array(); |
164 | 164 | |
165 | 165 | foreach ($rawHeaders as $line) { |
166 | - if (strpos($line, ':') === false) { |
|
166 | + if (strpos($line, ':') === false) { |
|
167 | 167 | $headers['http_code'] = $line; |
168 | - } else { |
|
168 | + } else { |
|
169 | 169 | list ($key, $value) = explode(': ', $line); |
170 | 170 | $headers[$key] = $value; |
171 | - } |
|
171 | + } |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | return $headers; |
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Pulls out the HTTP status code from a response header |
|
179 | - * |
|
180 | - * @param string $header |
|
181 | - * |
|
182 | - * @return int |
|
183 | - */ |
|
184 | - public static function getStatusCodeFromHeader($header) |
|
185 | - { |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Pulls out the HTTP status code from a response header |
|
179 | + * |
|
180 | + * @param string $header |
|
181 | + * |
|
182 | + * @return int |
|
183 | + */ |
|
184 | + public static function getStatusCodeFromHeader($header) |
|
185 | + { |
|
186 | 186 | preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $header, $match); |
187 | 187 | return (int) $match[1]; |
188 | - } |
|
188 | + } |
|
189 | 189 | |
190 | 190 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | 'verify_peer' => true, |
110 | 110 | 'verify_peer_name' => true, |
111 | 111 | 'allow_self_signed' => true, // All root certificates are self-signed |
112 | - 'cafile' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
112 | + 'cafile' => __DIR__.'/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
113 | 113 | ), |
114 | 114 | ); |
115 | 115 | |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | public function compileHeader() |
144 | 144 | { |
145 | 145 | $header = []; |
146 | - foreach($this->requestHeaders as $k => $v) { |
|
147 | - $header[] = $k . ': ' . $v; |
|
146 | + foreach ($this->requestHeaders as $k => $v) { |
|
147 | + $header[] = $k.': '.$v; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | return implode("\r\n", $header); |
@@ -35,333 +35,333 @@ |
||
35 | 35 | class FacebookSession |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - private static $defaultAppId; |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + private static $defaultAppId; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - private static $defaultAppSecret; |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + private static $defaultAppSecret; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var AccessToken The AccessToken entity for this connection. |
|
50 | - */ |
|
51 | - private $accessToken; |
|
48 | + /** |
|
49 | + * @var AccessToken The AccessToken entity for this connection. |
|
50 | + */ |
|
51 | + private $accessToken; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var SignedRequest |
|
55 | - */ |
|
56 | - private $signedRequest; |
|
53 | + /** |
|
54 | + * @var SignedRequest |
|
55 | + */ |
|
56 | + private $signedRequest; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @var bool |
|
60 | - */ |
|
61 | - protected static $useAppSecretProof = true; |
|
58 | + /** |
|
59 | + * @var bool |
|
60 | + */ |
|
61 | + protected static $useAppSecretProof = true; |
|
62 | 62 | |
63 | - /** |
|
64 | - * When creating a Session from an access_token, use: |
|
65 | - * var $session = new FacebookSession($accessToken); |
|
66 | - * This will validate the token and provide a Session object ready for use. |
|
67 | - * It will throw a SessionException in case of error. |
|
68 | - * |
|
69 | - * @param AccessToken|string $accessToken |
|
70 | - * @param SignedRequest $signedRequest The SignedRequest entity |
|
71 | - */ |
|
72 | - public function __construct($accessToken, SignedRequest $signedRequest = null) |
|
73 | - { |
|
63 | + /** |
|
64 | + * When creating a Session from an access_token, use: |
|
65 | + * var $session = new FacebookSession($accessToken); |
|
66 | + * This will validate the token and provide a Session object ready for use. |
|
67 | + * It will throw a SessionException in case of error. |
|
68 | + * |
|
69 | + * @param AccessToken|string $accessToken |
|
70 | + * @param SignedRequest $signedRequest The SignedRequest entity |
|
71 | + */ |
|
72 | + public function __construct($accessToken, SignedRequest $signedRequest = null) |
|
73 | + { |
|
74 | 74 | $this->accessToken = $accessToken instanceof AccessToken ? $accessToken : new AccessToken($accessToken); |
75 | 75 | $this->signedRequest = $signedRequest; |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Returns the access token. |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getToken() |
|
84 | - { |
|
78 | + /** |
|
79 | + * Returns the access token. |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getToken() |
|
84 | + { |
|
85 | 85 | return (string) $this->accessToken; |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Returns the access token entity. |
|
90 | - * |
|
91 | - * @return AccessToken |
|
92 | - */ |
|
93 | - public function getAccessToken() |
|
94 | - { |
|
88 | + /** |
|
89 | + * Returns the access token entity. |
|
90 | + * |
|
91 | + * @return AccessToken |
|
92 | + */ |
|
93 | + public function getAccessToken() |
|
94 | + { |
|
95 | 95 | return $this->accessToken; |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Returns the SignedRequest entity. |
|
100 | - * |
|
101 | - * @return SignedRequest |
|
102 | - */ |
|
103 | - public function getSignedRequest() |
|
104 | - { |
|
98 | + /** |
|
99 | + * Returns the SignedRequest entity. |
|
100 | + * |
|
101 | + * @return SignedRequest |
|
102 | + */ |
|
103 | + public function getSignedRequest() |
|
104 | + { |
|
105 | 105 | return $this->signedRequest; |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Returns the signed request payload. |
|
110 | - * |
|
111 | - * @return null|array |
|
112 | - */ |
|
113 | - public function getSignedRequestData() |
|
114 | - { |
|
108 | + /** |
|
109 | + * Returns the signed request payload. |
|
110 | + * |
|
111 | + * @return null|array |
|
112 | + */ |
|
113 | + public function getSignedRequestData() |
|
114 | + { |
|
115 | 115 | return $this->signedRequest ? $this->signedRequest->getPayload() : null; |
116 | - } |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Returns a property from the signed request data if available. |
|
120 | - * |
|
121 | - * @param string $key |
|
122 | - * |
|
123 | - * @return null|mixed |
|
124 | - */ |
|
125 | - public function getSignedRequestProperty($key) |
|
126 | - { |
|
118 | + /** |
|
119 | + * Returns a property from the signed request data if available. |
|
120 | + * |
|
121 | + * @param string $key |
|
122 | + * |
|
123 | + * @return null|mixed |
|
124 | + */ |
|
125 | + public function getSignedRequestProperty($key) |
|
126 | + { |
|
127 | 127 | return $this->signedRequest ? $this->signedRequest->get($key) : null; |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Returns user_id from signed request data if available. |
|
132 | - * |
|
133 | - * @return null|string |
|
134 | - */ |
|
135 | - public function getUserId() |
|
136 | - { |
|
130 | + /** |
|
131 | + * Returns user_id from signed request data if available. |
|
132 | + * |
|
133 | + * @return null|string |
|
134 | + */ |
|
135 | + public function getUserId() |
|
136 | + { |
|
137 | 137 | return $this->signedRequest ? $this->signedRequest->getUserId() : null; |
138 | - } |
|
138 | + } |
|
139 | 139 | |
140 | - // @TODO Remove getSessionInfo() in 4.1: can be accessed from AccessToken directly |
|
141 | - /** |
|
142 | - * getSessionInfo - Makes a request to /debug_token with the appropriate |
|
143 | - * arguments to get debug information about the sessions token. |
|
144 | - * |
|
145 | - * @param string|null $appId |
|
146 | - * @param string|null $appSecret |
|
147 | - * |
|
148 | - * @return GraphSessionInfo |
|
149 | - */ |
|
150 | - public function getSessionInfo($appId = null, $appSecret = null) |
|
151 | - { |
|
140 | + // @TODO Remove getSessionInfo() in 4.1: can be accessed from AccessToken directly |
|
141 | + /** |
|
142 | + * getSessionInfo - Makes a request to /debug_token with the appropriate |
|
143 | + * arguments to get debug information about the sessions token. |
|
144 | + * |
|
145 | + * @param string|null $appId |
|
146 | + * @param string|null $appSecret |
|
147 | + * |
|
148 | + * @return GraphSessionInfo |
|
149 | + */ |
|
150 | + public function getSessionInfo($appId = null, $appSecret = null) |
|
151 | + { |
|
152 | 152 | return $this->accessToken->getInfo($appId, $appSecret); |
153 | - } |
|
153 | + } |
|
154 | 154 | |
155 | - // @TODO Remove getLongLivedSession() in 4.1: can be accessed from AccessToken directly |
|
156 | - /** |
|
157 | - * getLongLivedSession - Returns a new Facebook session resulting from |
|
158 | - * extending a short-lived access token. If this session is not |
|
159 | - * short-lived, returns $this. |
|
160 | - * |
|
161 | - * @param string|null $appId |
|
162 | - * @param string|null $appSecret |
|
163 | - * |
|
164 | - * @return FacebookSession |
|
165 | - */ |
|
166 | - public function getLongLivedSession($appId = null, $appSecret = null) |
|
167 | - { |
|
155 | + // @TODO Remove getLongLivedSession() in 4.1: can be accessed from AccessToken directly |
|
156 | + /** |
|
157 | + * getLongLivedSession - Returns a new Facebook session resulting from |
|
158 | + * extending a short-lived access token. If this session is not |
|
159 | + * short-lived, returns $this. |
|
160 | + * |
|
161 | + * @param string|null $appId |
|
162 | + * @param string|null $appSecret |
|
163 | + * |
|
164 | + * @return FacebookSession |
|
165 | + */ |
|
166 | + public function getLongLivedSession($appId = null, $appSecret = null) |
|
167 | + { |
|
168 | 168 | $longLivedAccessToken = $this->accessToken->extend($appId, $appSecret); |
169 | 169 | return new static($longLivedAccessToken, $this->signedRequest); |
170 | - } |
|
170 | + } |
|
171 | 171 | |
172 | - // @TODO Remove getExchangeToken() in 4.1: can be accessed from AccessToken directly |
|
173 | - /** |
|
174 | - * getExchangeToken - Returns an exchange token string which can be sent |
|
175 | - * back to clients and exchanged for a device-linked access token. |
|
176 | - * |
|
177 | - * @param string|null $appId |
|
178 | - * @param string|null $appSecret |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function getExchangeToken($appId = null, $appSecret = null) |
|
183 | - { |
|
172 | + // @TODO Remove getExchangeToken() in 4.1: can be accessed from AccessToken directly |
|
173 | + /** |
|
174 | + * getExchangeToken - Returns an exchange token string which can be sent |
|
175 | + * back to clients and exchanged for a device-linked access token. |
|
176 | + * |
|
177 | + * @param string|null $appId |
|
178 | + * @param string|null $appSecret |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function getExchangeToken($appId = null, $appSecret = null) |
|
183 | + { |
|
184 | 184 | return AccessToken::getCodeFromAccessToken($this->accessToken, $appId, $appSecret); |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - // @TODO Remove validate() in 4.1: can be accessed from AccessToken directly |
|
188 | - /** |
|
189 | - * validate - Ensures the current session is valid, throwing an exception if |
|
190 | - * not. Fetches token info from Facebook. |
|
191 | - * |
|
192 | - * @param string|null $appId Application ID to use |
|
193 | - * @param string|null $appSecret App secret value to use |
|
194 | - * @param string|null $machineId |
|
195 | - * |
|
196 | - * @return boolean |
|
197 | - * |
|
198 | - * @throws FacebookSDKException |
|
199 | - */ |
|
200 | - public function validate($appId = null, $appSecret = null, $machineId = null) |
|
201 | - { |
|
187 | + // @TODO Remove validate() in 4.1: can be accessed from AccessToken directly |
|
188 | + /** |
|
189 | + * validate - Ensures the current session is valid, throwing an exception if |
|
190 | + * not. Fetches token info from Facebook. |
|
191 | + * |
|
192 | + * @param string|null $appId Application ID to use |
|
193 | + * @param string|null $appSecret App secret value to use |
|
194 | + * @param string|null $machineId |
|
195 | + * |
|
196 | + * @return boolean |
|
197 | + * |
|
198 | + * @throws FacebookSDKException |
|
199 | + */ |
|
200 | + public function validate($appId = null, $appSecret = null, $machineId = null) |
|
201 | + { |
|
202 | 202 | if ($this->accessToken->isValid($appId, $appSecret, $machineId)) { |
203 | - return true; |
|
203 | + return true; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // @TODO For v4.1 this should not throw an exception, but just return false. |
207 | 207 | throw new FacebookSDKException( |
208 | - 'Session has expired, or is not valid for this app.', 601 |
|
208 | + 'Session has expired, or is not valid for this app.', 601 |
|
209 | 209 | ); |
210 | - } |
|
210 | + } |
|
211 | 211 | |
212 | - // @TODO Remove validateSessionInfo() in 4.1: can be accessed from AccessToken directly |
|
213 | - /** |
|
214 | - * validateTokenInfo - Ensures the provided GraphSessionInfo object is valid, |
|
215 | - * throwing an exception if not. Ensures the appId matches, |
|
216 | - * that the token is valid and has not expired. |
|
217 | - * |
|
218 | - * @param GraphSessionInfo $tokenInfo |
|
219 | - * @param string|null $appId Application ID to use |
|
220 | - * @param string|null $machineId |
|
221 | - * |
|
222 | - * @return boolean |
|
223 | - * |
|
224 | - * @throws FacebookSDKException |
|
225 | - */ |
|
226 | - public static function validateSessionInfo(GraphSessionInfo $tokenInfo, |
|
227 | - $appId = null, |
|
228 | - $machineId = null) |
|
229 | - { |
|
212 | + // @TODO Remove validateSessionInfo() in 4.1: can be accessed from AccessToken directly |
|
213 | + /** |
|
214 | + * validateTokenInfo - Ensures the provided GraphSessionInfo object is valid, |
|
215 | + * throwing an exception if not. Ensures the appId matches, |
|
216 | + * that the token is valid and has not expired. |
|
217 | + * |
|
218 | + * @param GraphSessionInfo $tokenInfo |
|
219 | + * @param string|null $appId Application ID to use |
|
220 | + * @param string|null $machineId |
|
221 | + * |
|
222 | + * @return boolean |
|
223 | + * |
|
224 | + * @throws FacebookSDKException |
|
225 | + */ |
|
226 | + public static function validateSessionInfo(GraphSessionInfo $tokenInfo, |
|
227 | + $appId = null, |
|
228 | + $machineId = null) |
|
229 | + { |
|
230 | 230 | if (AccessToken::validateAccessToken($tokenInfo, $appId, $machineId)) { |
231 | - return true; |
|
231 | + return true; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | // @TODO For v4.1 this should not throw an exception, but just return false. |
235 | 235 | throw new FacebookSDKException( |
236 | - 'Session has expired, or is not valid for this app.', 601 |
|
236 | + 'Session has expired, or is not valid for this app.', 601 |
|
237 | 237 | ); |
238 | - } |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * newSessionFromSignedRequest - Returns a FacebookSession for a |
|
242 | - * given signed request. |
|
243 | - * |
|
244 | - * @param SignedRequest $signedRequest |
|
245 | - * |
|
246 | - * @return FacebookSession |
|
247 | - */ |
|
248 | - public static function newSessionFromSignedRequest(SignedRequest $signedRequest) |
|
249 | - { |
|
240 | + /** |
|
241 | + * newSessionFromSignedRequest - Returns a FacebookSession for a |
|
242 | + * given signed request. |
|
243 | + * |
|
244 | + * @param SignedRequest $signedRequest |
|
245 | + * |
|
246 | + * @return FacebookSession |
|
247 | + */ |
|
248 | + public static function newSessionFromSignedRequest(SignedRequest $signedRequest) |
|
249 | + { |
|
250 | 250 | if ($signedRequest->get('code') |
251 | 251 | && !$signedRequest->get('oauth_token')) { |
252 | - return self::newSessionAfterValidation($signedRequest); |
|
252 | + return self::newSessionAfterValidation($signedRequest); |
|
253 | 253 | } |
254 | 254 | $accessToken = $signedRequest->get('oauth_token'); |
255 | 255 | $expiresAt = $signedRequest->get('expires', 0); |
256 | 256 | $accessToken = new AccessToken($accessToken, $expiresAt); |
257 | 257 | return new static($accessToken, $signedRequest); |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * newSessionAfterValidation - Returns a FacebookSession for a |
|
262 | - * validated & parsed signed request. |
|
263 | - * |
|
264 | - * @param SignedRequest $signedRequest |
|
265 | - * |
|
266 | - * @return FacebookSession |
|
267 | - */ |
|
268 | - protected static function newSessionAfterValidation(SignedRequest $signedRequest) |
|
269 | - { |
|
260 | + /** |
|
261 | + * newSessionAfterValidation - Returns a FacebookSession for a |
|
262 | + * validated & parsed signed request. |
|
263 | + * |
|
264 | + * @param SignedRequest $signedRequest |
|
265 | + * |
|
266 | + * @return FacebookSession |
|
267 | + */ |
|
268 | + protected static function newSessionAfterValidation(SignedRequest $signedRequest) |
|
269 | + { |
|
270 | 270 | $code = $signedRequest->get('code'); |
271 | 271 | $accessToken = AccessToken::getAccessTokenFromCode($code); |
272 | 272 | return new static($accessToken, $signedRequest); |
273 | - } |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * newAppSession - Returns a FacebookSession configured with a token for the |
|
277 | - * application which can be used for publishing and requesting app-level |
|
278 | - * information. |
|
279 | - * |
|
280 | - * @param string|null $appId Application ID to use |
|
281 | - * @param string|null $appSecret App secret value to use |
|
282 | - * |
|
283 | - * @return FacebookSession |
|
284 | - */ |
|
285 | - public static function newAppSession($appId = null, $appSecret = null) |
|
286 | - { |
|
275 | + /** |
|
276 | + * newAppSession - Returns a FacebookSession configured with a token for the |
|
277 | + * application which can be used for publishing and requesting app-level |
|
278 | + * information. |
|
279 | + * |
|
280 | + * @param string|null $appId Application ID to use |
|
281 | + * @param string|null $appSecret App secret value to use |
|
282 | + * |
|
283 | + * @return FacebookSession |
|
284 | + */ |
|
285 | + public static function newAppSession($appId = null, $appSecret = null) |
|
286 | + { |
|
287 | 287 | $targetAppId = static::_getTargetAppId($appId); |
288 | 288 | $targetAppSecret = static::_getTargetAppSecret($appSecret); |
289 | 289 | return new FacebookSession( |
290 | - $targetAppId . '|' . $targetAppSecret |
|
290 | + $targetAppId . '|' . $targetAppSecret |
|
291 | 291 | ); |
292 | - } |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * setDefaultApplication - Will set the static default appId and appSecret |
|
296 | - * to be used for API requests. |
|
297 | - * |
|
298 | - * @param string $appId Application ID to use by default |
|
299 | - * @param string $appSecret App secret value to use by default |
|
300 | - */ |
|
301 | - public static function setDefaultApplication($appId, $appSecret) |
|
302 | - { |
|
294 | + /** |
|
295 | + * setDefaultApplication - Will set the static default appId and appSecret |
|
296 | + * to be used for API requests. |
|
297 | + * |
|
298 | + * @param string $appId Application ID to use by default |
|
299 | + * @param string $appSecret App secret value to use by default |
|
300 | + */ |
|
301 | + public static function setDefaultApplication($appId, $appSecret) |
|
302 | + { |
|
303 | 303 | self::$defaultAppId = $appId; |
304 | 304 | self::$defaultAppSecret = $appSecret; |
305 | - } |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * _getTargetAppId - Will return either the provided app Id or the default, |
|
309 | - * throwing if neither are populated. |
|
310 | - * |
|
311 | - * @param string $appId |
|
312 | - * |
|
313 | - * @return string |
|
314 | - * |
|
315 | - * @throws FacebookSDKException |
|
316 | - */ |
|
317 | - public static function _getTargetAppId($appId = null) { |
|
307 | + /** |
|
308 | + * _getTargetAppId - Will return either the provided app Id or the default, |
|
309 | + * throwing if neither are populated. |
|
310 | + * |
|
311 | + * @param string $appId |
|
312 | + * |
|
313 | + * @return string |
|
314 | + * |
|
315 | + * @throws FacebookSDKException |
|
316 | + */ |
|
317 | + public static function _getTargetAppId($appId = null) { |
|
318 | 318 | $target = ($appId ?: self::$defaultAppId); |
319 | 319 | if (!$target) { |
320 | - throw new FacebookSDKException( |
|
320 | + throw new FacebookSDKException( |
|
321 | 321 | 'You must provide or set a default application id.', 700 |
322 | - ); |
|
322 | + ); |
|
323 | 323 | } |
324 | 324 | return $target; |
325 | - } |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * _getTargetAppSecret - Will return either the provided app secret or the |
|
329 | - * default, throwing if neither are populated. |
|
330 | - * |
|
331 | - * @param string $appSecret |
|
332 | - * |
|
333 | - * @return string |
|
334 | - * |
|
335 | - * @throws FacebookSDKException |
|
336 | - */ |
|
337 | - public static function _getTargetAppSecret($appSecret = null) { |
|
327 | + /** |
|
328 | + * _getTargetAppSecret - Will return either the provided app secret or the |
|
329 | + * default, throwing if neither are populated. |
|
330 | + * |
|
331 | + * @param string $appSecret |
|
332 | + * |
|
333 | + * @return string |
|
334 | + * |
|
335 | + * @throws FacebookSDKException |
|
336 | + */ |
|
337 | + public static function _getTargetAppSecret($appSecret = null) { |
|
338 | 338 | $target = ($appSecret ?: self::$defaultAppSecret); |
339 | 339 | if (!$target) { |
340 | - throw new FacebookSDKException( |
|
340 | + throw new FacebookSDKException( |
|
341 | 341 | 'You must provide or set a default application secret.', 701 |
342 | - ); |
|
342 | + ); |
|
343 | 343 | } |
344 | 344 | return $target; |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
348 | - * Enable or disable sending the appsecret_proof with requests. |
|
349 | - * |
|
350 | - * @param bool $on |
|
351 | - */ |
|
352 | - public static function enableAppSecretProof($on = true) |
|
353 | - { |
|
347 | + /** |
|
348 | + * Enable or disable sending the appsecret_proof with requests. |
|
349 | + * |
|
350 | + * @param bool $on |
|
351 | + */ |
|
352 | + public static function enableAppSecretProof($on = true) |
|
353 | + { |
|
354 | 354 | static::$useAppSecretProof = ($on ? true : false); |
355 | - } |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * Get whether or not appsecret_proof should be sent with requests. |
|
359 | - * |
|
360 | - * @return bool |
|
361 | - */ |
|
362 | - public static function useAppSecretProof() |
|
363 | - { |
|
357 | + /** |
|
358 | + * Get whether or not appsecret_proof should be sent with requests. |
|
359 | + * |
|
360 | + * @return bool |
|
361 | + */ |
|
362 | + public static function useAppSecretProof() |
|
363 | + { |
|
364 | 364 | return static::$useAppSecretProof; |
365 | - } |
|
365 | + } |
|
366 | 366 | |
367 | 367 | } |
@@ -287,7 +287,7 @@ |
||
287 | 287 | $targetAppId = static::_getTargetAppId($appId); |
288 | 288 | $targetAppSecret = static::_getTargetAppSecret($appSecret); |
289 | 289 | return new FacebookSession( |
290 | - $targetAppId . '|' . $targetAppSecret |
|
290 | + $targetAppId.'|'.$targetAppSecret |
|
291 | 291 | ); |
292 | 292 | } |
293 | 293 |
@@ -32,140 +32,140 @@ |
||
32 | 32 | class GraphObject |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var array - Holds the raw associative data for this object |
|
37 | - */ |
|
38 | - protected $backingData; |
|
35 | + /** |
|
36 | + * @var array - Holds the raw associative data for this object |
|
37 | + */ |
|
38 | + protected $backingData; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Creates a GraphObject using the data provided. |
|
42 | - * |
|
43 | - * @param array $raw |
|
44 | - */ |
|
45 | - public function __construct($raw) |
|
46 | - { |
|
40 | + /** |
|
41 | + * Creates a GraphObject using the data provided. |
|
42 | + * |
|
43 | + * @param array $raw |
|
44 | + */ |
|
45 | + public function __construct($raw) |
|
46 | + { |
|
47 | 47 | if ($raw instanceof \stdClass) { |
48 | - $raw = get_object_vars($raw); |
|
48 | + $raw = get_object_vars($raw); |
|
49 | 49 | } |
50 | 50 | $this->backingData = $raw; |
51 | 51 | |
52 | 52 | if (isset($this->backingData['data']) && count($this->backingData) === 1) { |
53 | - if ($this->backingData['data'] instanceof \stdClass) { |
|
53 | + if ($this->backingData['data'] instanceof \stdClass) { |
|
54 | 54 | $this->backingData = get_object_vars($this->backingData['data']); |
55 | - } else { |
|
55 | + } else { |
|
56 | 56 | $this->backingData = $this->backingData['data']; |
57 | - } |
|
57 | + } |
|
58 | + } |
|
58 | 59 | } |
59 | - } |
|
60 | 60 | |
61 | - /** |
|
62 | - * cast - Return a new instance of a FacebookGraphObject subclass for this |
|
63 | - * objects underlying data. |
|
64 | - * |
|
65 | - * @param string $type The GraphObject subclass to cast to |
|
66 | - * |
|
67 | - * @return GraphObject |
|
68 | - * |
|
69 | - * @throws FacebookSDKException |
|
70 | - */ |
|
71 | - public function cast($type) |
|
72 | - { |
|
61 | + /** |
|
62 | + * cast - Return a new instance of a FacebookGraphObject subclass for this |
|
63 | + * objects underlying data. |
|
64 | + * |
|
65 | + * @param string $type The GraphObject subclass to cast to |
|
66 | + * |
|
67 | + * @return GraphObject |
|
68 | + * |
|
69 | + * @throws FacebookSDKException |
|
70 | + */ |
|
71 | + public function cast($type) |
|
72 | + { |
|
73 | 73 | if ($this instanceof $type) { |
74 | - return $this; |
|
74 | + return $this; |
|
75 | 75 | } |
76 | 76 | if (is_subclass_of($type, GraphObject::className())) { |
77 | - return new $type($this->backingData); |
|
77 | + return new $type($this->backingData); |
|
78 | 78 | } else { |
79 | - throw new FacebookSDKException( |
|
79 | + throw new FacebookSDKException( |
|
80 | 80 | 'Cannot cast to an object that is not a GraphObject subclass', 620 |
81 | - ); |
|
81 | + ); |
|
82 | + } |
|
82 | 83 | } |
83 | - } |
|
84 | 84 | |
85 | - /** |
|
86 | - * asArray - Return a key-value associative array for the given graph object. |
|
87 | - * |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public function asArray() |
|
91 | - { |
|
85 | + /** |
|
86 | + * asArray - Return a key-value associative array for the given graph object. |
|
87 | + * |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public function asArray() |
|
91 | + { |
|
92 | 92 | return $this->backingData; |
93 | - } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * getProperty - Gets the value of the named property for this graph object, |
|
97 | - * cast to the appropriate subclass type if provided. |
|
98 | - * |
|
99 | - * @param string $name The property to retrieve |
|
100 | - * @param string $type The subclass of GraphObject, optionally |
|
101 | - * |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - public function getProperty($name, $type = 'Facebook\GraphObject') |
|
105 | - { |
|
95 | + /** |
|
96 | + * getProperty - Gets the value of the named property for this graph object, |
|
97 | + * cast to the appropriate subclass type if provided. |
|
98 | + * |
|
99 | + * @param string $name The property to retrieve |
|
100 | + * @param string $type The subclass of GraphObject, optionally |
|
101 | + * |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + public function getProperty($name, $type = 'Facebook\GraphObject') |
|
105 | + { |
|
106 | 106 | if (isset($this->backingData[$name])) { |
107 | - $value = $this->backingData[$name]; |
|
108 | - if (is_scalar($value)) { |
|
107 | + $value = $this->backingData[$name]; |
|
108 | + if (is_scalar($value)) { |
|
109 | 109 | return $value; |
110 | - } else { |
|
110 | + } else { |
|
111 | 111 | return (new GraphObject($value))->cast($type); |
112 | - } |
|
112 | + } |
|
113 | 113 | } else { |
114 | - return null; |
|
114 | + return null; |
|
115 | + } |
|
115 | 116 | } |
116 | - } |
|
117 | 117 | |
118 | - /** |
|
119 | - * getPropertyAsArray - Get the list value of a named property for this graph |
|
120 | - * object, where each item has been cast to the appropriate subclass type |
|
121 | - * if provided. |
|
122 | - * |
|
123 | - * Calling this for a property that is not an array, the behavior |
|
124 | - * is undefined, so don’t do this. |
|
125 | - * |
|
126 | - * @param string $name The property to retrieve |
|
127 | - * @param string $type The subclass of GraphObject, optionally |
|
128 | - * |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - public function getPropertyAsArray($name, $type = 'Facebook\GraphObject') |
|
132 | - { |
|
118 | + /** |
|
119 | + * getPropertyAsArray - Get the list value of a named property for this graph |
|
120 | + * object, where each item has been cast to the appropriate subclass type |
|
121 | + * if provided. |
|
122 | + * |
|
123 | + * Calling this for a property that is not an array, the behavior |
|
124 | + * is undefined, so don’t do this. |
|
125 | + * |
|
126 | + * @param string $name The property to retrieve |
|
127 | + * @param string $type The subclass of GraphObject, optionally |
|
128 | + * |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + public function getPropertyAsArray($name, $type = 'Facebook\GraphObject') |
|
132 | + { |
|
133 | 133 | $target = array(); |
134 | 134 | if (isset($this->backingData[$name]['data'])) { |
135 | - $target = $this->backingData[$name]['data']; |
|
135 | + $target = $this->backingData[$name]['data']; |
|
136 | 136 | } else if (isset($this->backingData[$name]) |
137 | 137 | && !is_scalar($this->backingData[$name])) { |
138 | - $target = $this->backingData[$name]; |
|
138 | + $target = $this->backingData[$name]; |
|
139 | 139 | } |
140 | 140 | $out = array(); |
141 | 141 | foreach ($target as $key => $value) { |
142 | - if (is_scalar($value)) { |
|
142 | + if (is_scalar($value)) { |
|
143 | 143 | $out[$key] = $value; |
144 | - } else { |
|
144 | + } else { |
|
145 | 145 | $out[$key] = (new GraphObject($value))->cast($type); |
146 | - } |
|
146 | + } |
|
147 | 147 | } |
148 | 148 | return $out; |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * getPropertyNames - Returns a list of all properties set on the object. |
|
153 | - * |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - public function getPropertyNames() |
|
157 | - { |
|
151 | + /** |
|
152 | + * getPropertyNames - Returns a list of all properties set on the object. |
|
153 | + * |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + public function getPropertyNames() |
|
157 | + { |
|
158 | 158 | return array_keys($this->backingData); |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Returns the string class name of the GraphObject or subclass. |
|
163 | - * |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - public static function className() |
|
167 | - { |
|
161 | + /** |
|
162 | + * Returns the string class name of the GraphObject or subclass. |
|
163 | + * |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + public static function className() |
|
167 | + { |
|
168 | 168 | return get_called_class(); |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | 171 | } |
172 | 172 | \ No newline at end of file |
@@ -31,54 +31,54 @@ |
||
31 | 31 | class GraphUserPage extends GraphObject |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the ID for the user's page as a string if present. |
|
36 | - * |
|
37 | - * @return string|null |
|
38 | - */ |
|
39 | - public function getId() |
|
40 | - { |
|
34 | + /** |
|
35 | + * Returns the ID for the user's page as a string if present. |
|
36 | + * |
|
37 | + * @return string|null |
|
38 | + */ |
|
39 | + public function getId() |
|
40 | + { |
|
41 | 41 | return $this->getProperty('id'); |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns the Category for the user's page as a string if present. |
|
46 | - * |
|
47 | - * @return string|null |
|
48 | - */ |
|
49 | - public function getCategory() |
|
50 | - { |
|
44 | + /** |
|
45 | + * Returns the Category for the user's page as a string if present. |
|
46 | + * |
|
47 | + * @return string|null |
|
48 | + */ |
|
49 | + public function getCategory() |
|
50 | + { |
|
51 | 51 | return $this->getProperty('category'); |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns the Name of the user's page as a string if present. |
|
56 | - * |
|
57 | - * @return string|null |
|
58 | - */ |
|
59 | - public function getName() |
|
60 | - { |
|
54 | + /** |
|
55 | + * Returns the Name of the user's page as a string if present. |
|
56 | + * |
|
57 | + * @return string|null |
|
58 | + */ |
|
59 | + public function getName() |
|
60 | + { |
|
61 | 61 | return $this->getProperty('name'); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns the Access Token used to access the user's page as a string if present. |
|
66 | - * |
|
67 | - * @return string|null |
|
68 | - */ |
|
69 | - public function getAccessToken() |
|
70 | - { |
|
64 | + /** |
|
65 | + * Returns the Access Token used to access the user's page as a string if present. |
|
66 | + * |
|
67 | + * @return string|null |
|
68 | + */ |
|
69 | + public function getAccessToken() |
|
70 | + { |
|
71 | 71 | return $this->getProperty('access_token'); |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Returns the Permissions for the user's page as an array if present. |
|
76 | - * |
|
77 | - * @return array|null |
|
78 | - */ |
|
79 | - public function getPermissions() |
|
80 | - { |
|
74 | + /** |
|
75 | + * Returns the Permissions for the user's page as an array if present. |
|
76 | + * |
|
77 | + * @return array|null |
|
78 | + */ |
|
79 | + public function getPermissions() |
|
80 | + { |
|
81 | 81 | return $this->getProperty('perms'); |
82 | - } |
|
82 | + } |
|
83 | 83 | |
84 | 84 | } |
85 | 85 | \ No newline at end of file |
@@ -116,7 +116,7 @@ |
||
116 | 116 | */ |
117 | 117 | public function getFrom() |
118 | 118 | { |
119 | - return $this->getProperty('from', GraphUser::className()); |
|
119 | + return $this->getProperty('from', GraphUser::className()); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -32,74 +32,74 @@ |
||
32 | 32 | class GraphLocation extends GraphObject |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Returns the street component of the location |
|
37 | - * |
|
38 | - * @return string|null |
|
39 | - */ |
|
40 | - public function getStreet() |
|
41 | - { |
|
35 | + /** |
|
36 | + * Returns the street component of the location |
|
37 | + * |
|
38 | + * @return string|null |
|
39 | + */ |
|
40 | + public function getStreet() |
|
41 | + { |
|
42 | 42 | return $this->getProperty('street'); |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns the city component of the location |
|
47 | - * |
|
48 | - * @return string|null |
|
49 | - */ |
|
50 | - public function getCity() |
|
51 | - { |
|
45 | + /** |
|
46 | + * Returns the city component of the location |
|
47 | + * |
|
48 | + * @return string|null |
|
49 | + */ |
|
50 | + public function getCity() |
|
51 | + { |
|
52 | 52 | return $this->getProperty('city'); |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the state component of the location |
|
57 | - * |
|
58 | - * @return string|null |
|
59 | - */ |
|
60 | - public function getState() |
|
61 | - { |
|
55 | + /** |
|
56 | + * Returns the state component of the location |
|
57 | + * |
|
58 | + * @return string|null |
|
59 | + */ |
|
60 | + public function getState() |
|
61 | + { |
|
62 | 62 | return $this->getProperty('state'); |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns the country component of the location |
|
67 | - * |
|
68 | - * @return string|null |
|
69 | - */ |
|
70 | - public function getCountry() |
|
71 | - { |
|
65 | + /** |
|
66 | + * Returns the country component of the location |
|
67 | + * |
|
68 | + * @return string|null |
|
69 | + */ |
|
70 | + public function getCountry() |
|
71 | + { |
|
72 | 72 | return $this->getProperty('country'); |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns the zipcode component of the location |
|
77 | - * |
|
78 | - * @return string|null |
|
79 | - */ |
|
80 | - public function getZip() |
|
81 | - { |
|
75 | + /** |
|
76 | + * Returns the zipcode component of the location |
|
77 | + * |
|
78 | + * @return string|null |
|
79 | + */ |
|
80 | + public function getZip() |
|
81 | + { |
|
82 | 82 | return $this->getProperty('zip'); |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Returns the latitude component of the location |
|
87 | - * |
|
88 | - * @return float|null |
|
89 | - */ |
|
90 | - public function getLatitude() |
|
91 | - { |
|
85 | + /** |
|
86 | + * Returns the latitude component of the location |
|
87 | + * |
|
88 | + * @return float|null |
|
89 | + */ |
|
90 | + public function getLatitude() |
|
91 | + { |
|
92 | 92 | return $this->getProperty('latitude'); |
93 | - } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Returns the street component of the location |
|
97 | - * |
|
98 | - * @return float|null |
|
99 | - */ |
|
100 | - public function getLongitude() |
|
101 | - { |
|
95 | + /** |
|
96 | + * Returns the street component of the location |
|
97 | + * |
|
98 | + * @return float|null |
|
99 | + */ |
|
100 | + public function getLongitude() |
|
101 | + { |
|
102 | 102 | return $this->getProperty('longitude'); |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | 105 | } |
106 | 106 | \ No newline at end of file |
@@ -36,202 +36,202 @@ discard block |
||
36 | 36 | class FacebookRequest |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * @const string Version number of the Facebook PHP SDK. |
|
41 | - */ |
|
42 | - const VERSION = '4.0.15'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @const string Default Graph API version for requests |
|
46 | - */ |
|
47 | - const GRAPH_API_VERSION = 'v2.2'; |
|
48 | - |
|
49 | - /** |
|
50 | - * @const string Graph API URL |
|
51 | - */ |
|
52 | - const BASE_GRAPH_URL = 'https://graph.facebook.com'; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var FacebookSession The session used for this request |
|
56 | - */ |
|
57 | - private $session; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var string The HTTP method for the request |
|
61 | - */ |
|
62 | - private $method; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string The path for the request |
|
66 | - */ |
|
67 | - private $path; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var array The parameters for the request |
|
71 | - */ |
|
72 | - private $params; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var string The Graph API version for the request |
|
76 | - */ |
|
77 | - private $version; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var string ETag sent with the request |
|
81 | - */ |
|
82 | - private $etag; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var FacebookHttpable HTTP client handler |
|
86 | - */ |
|
87 | - private static $httpClientHandler; |
|
88 | - |
|
89 | - /** |
|
90 | - * @var int The number of calls that have been made to Graph. |
|
91 | - */ |
|
92 | - public static $requestCount = 0; |
|
93 | - |
|
94 | - /** |
|
95 | - * getSession - Returns the associated FacebookSession. |
|
96 | - * |
|
97 | - * @return FacebookSession |
|
98 | - */ |
|
99 | - public function getSession() |
|
100 | - { |
|
39 | + /** |
|
40 | + * @const string Version number of the Facebook PHP SDK. |
|
41 | + */ |
|
42 | + const VERSION = '4.0.15'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @const string Default Graph API version for requests |
|
46 | + */ |
|
47 | + const GRAPH_API_VERSION = 'v2.2'; |
|
48 | + |
|
49 | + /** |
|
50 | + * @const string Graph API URL |
|
51 | + */ |
|
52 | + const BASE_GRAPH_URL = 'https://graph.facebook.com'; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var FacebookSession The session used for this request |
|
56 | + */ |
|
57 | + private $session; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var string The HTTP method for the request |
|
61 | + */ |
|
62 | + private $method; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string The path for the request |
|
66 | + */ |
|
67 | + private $path; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var array The parameters for the request |
|
71 | + */ |
|
72 | + private $params; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var string The Graph API version for the request |
|
76 | + */ |
|
77 | + private $version; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var string ETag sent with the request |
|
81 | + */ |
|
82 | + private $etag; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var FacebookHttpable HTTP client handler |
|
86 | + */ |
|
87 | + private static $httpClientHandler; |
|
88 | + |
|
89 | + /** |
|
90 | + * @var int The number of calls that have been made to Graph. |
|
91 | + */ |
|
92 | + public static $requestCount = 0; |
|
93 | + |
|
94 | + /** |
|
95 | + * getSession - Returns the associated FacebookSession. |
|
96 | + * |
|
97 | + * @return FacebookSession |
|
98 | + */ |
|
99 | + public function getSession() |
|
100 | + { |
|
101 | 101 | return $this->session; |
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * getPath - Returns the associated path. |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getPath() |
|
110 | - { |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * getPath - Returns the associated path. |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getPath() |
|
110 | + { |
|
111 | 111 | return $this->path; |
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * getParameters - Returns the associated parameters. |
|
116 | - * |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public function getParameters() |
|
120 | - { |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * getParameters - Returns the associated parameters. |
|
116 | + * |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public function getParameters() |
|
120 | + { |
|
121 | 121 | return $this->params; |
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * getMethod - Returns the associated method. |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getMethod() |
|
130 | - { |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * getMethod - Returns the associated method. |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getMethod() |
|
130 | + { |
|
131 | 131 | return $this->method; |
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * getETag - Returns the ETag sent with the request. |
|
136 | - * |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function getETag() |
|
140 | - { |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * getETag - Returns the ETag sent with the request. |
|
136 | + * |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function getETag() |
|
140 | + { |
|
141 | 141 | return $this->etag; |
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * setHttpClientHandler - Returns an instance of the HTTP client |
|
146 | - * handler |
|
147 | - * |
|
148 | - * @param \Facebook\HttpClients\FacebookHttpable |
|
149 | - */ |
|
150 | - public static function setHttpClientHandler(FacebookHttpable $handler) |
|
151 | - { |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * setHttpClientHandler - Returns an instance of the HTTP client |
|
146 | + * handler |
|
147 | + * |
|
148 | + * @param \Facebook\HttpClients\FacebookHttpable |
|
149 | + */ |
|
150 | + public static function setHttpClientHandler(FacebookHttpable $handler) |
|
151 | + { |
|
152 | 152 | static::$httpClientHandler = $handler; |
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * getHttpClientHandler - Returns an instance of the HTTP client |
|
157 | - * data handler |
|
158 | - * |
|
159 | - * @return FacebookHttpable |
|
160 | - */ |
|
161 | - public static function getHttpClientHandler() |
|
162 | - { |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * getHttpClientHandler - Returns an instance of the HTTP client |
|
157 | + * data handler |
|
158 | + * |
|
159 | + * @return FacebookHttpable |
|
160 | + */ |
|
161 | + public static function getHttpClientHandler() |
|
162 | + { |
|
163 | 163 | if (static::$httpClientHandler) { |
164 | - return static::$httpClientHandler; |
|
164 | + return static::$httpClientHandler; |
|
165 | 165 | } |
166 | 166 | return function_exists('curl_init') ? new FacebookCurlHttpClient() : new FacebookStreamHttpClient(); |
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * FacebookRequest - Returns a new request using the given session. optional |
|
171 | - * parameters hash will be sent with the request. This object is |
|
172 | - * immutable. |
|
173 | - * |
|
174 | - * @param FacebookSession $session |
|
175 | - * @param string $method |
|
176 | - * @param string $path |
|
177 | - * @param array|null $parameters |
|
178 | - * @param string|null $version |
|
179 | - * @param string|null $etag |
|
180 | - */ |
|
181 | - public function __construct( |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * FacebookRequest - Returns a new request using the given session. optional |
|
171 | + * parameters hash will be sent with the request. This object is |
|
172 | + * immutable. |
|
173 | + * |
|
174 | + * @param FacebookSession $session |
|
175 | + * @param string $method |
|
176 | + * @param string $path |
|
177 | + * @param array|null $parameters |
|
178 | + * @param string|null $version |
|
179 | + * @param string|null $etag |
|
180 | + */ |
|
181 | + public function __construct( |
|
182 | 182 | FacebookSession $session, $method, $path, $parameters = null, $version = null, $etag = null |
183 | - ) |
|
184 | - { |
|
183 | + ) |
|
184 | + { |
|
185 | 185 | $this->session = $session; |
186 | 186 | $this->method = $method; |
187 | 187 | $this->path = $path; |
188 | 188 | if ($version) { |
189 | - $this->version = $version; |
|
189 | + $this->version = $version; |
|
190 | 190 | } else { |
191 | - $this->version = static::GRAPH_API_VERSION; |
|
191 | + $this->version = static::GRAPH_API_VERSION; |
|
192 | 192 | } |
193 | 193 | $this->etag = $etag; |
194 | 194 | |
195 | 195 | $params = ($parameters ?: array()); |
196 | 196 | if ($session |
197 | 197 | && !isset($params["access_token"])) { |
198 | - $params["access_token"] = $session->getToken(); |
|
198 | + $params["access_token"] = $session->getToken(); |
|
199 | 199 | } |
200 | 200 | if (FacebookSession::useAppSecretProof() |
201 | 201 | && !isset($params["appsecret_proof"])) { |
202 | - $params["appsecret_proof"] = $this->getAppSecretProof( |
|
202 | + $params["appsecret_proof"] = $this->getAppSecretProof( |
|
203 | 203 | $params["access_token"] |
204 | - ); |
|
204 | + ); |
|
205 | 205 | } |
206 | 206 | $this->params = $params; |
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Returns the base Graph URL. |
|
211 | - * |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - protected function getRequestURL() |
|
215 | - { |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Returns the base Graph URL. |
|
211 | + * |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + protected function getRequestURL() |
|
215 | + { |
|
216 | 216 | return static::BASE_GRAPH_URL . '/' . $this->version . $this->path; |
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * execute - Makes the request to Facebook and returns the result. |
|
221 | - * |
|
222 | - * @return FacebookResponse |
|
223 | - * |
|
224 | - * @throws FacebookSDKException |
|
225 | - * @throws FacebookRequestException |
|
226 | - */ |
|
227 | - public function execute() |
|
228 | - { |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * execute - Makes the request to Facebook and returns the result. |
|
221 | + * |
|
222 | + * @return FacebookResponse |
|
223 | + * |
|
224 | + * @throws FacebookSDKException |
|
225 | + * @throws FacebookRequestException |
|
226 | + */ |
|
227 | + public function execute() |
|
228 | + { |
|
229 | 229 | $url = $this->getRequestURL(); |
230 | 230 | $params = $this->getParameters(); |
231 | 231 | |
232 | 232 | if ($this->method === "GET") { |
233 | - $url = self::appendParamsToUrl($url, $params); |
|
234 | - $params = array(); |
|
233 | + $url = self::appendParamsToUrl($url, $params); |
|
234 | + $params = array(); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $connection = self::getHttpClientHandler(); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | |
241 | 241 | // ETag |
242 | 242 | if (isset($this->etag)) { |
243 | - $connection->addRequestHeader('If-None-Match', $this->etag); |
|
243 | + $connection->addRequestHeader('If-None-Match', $this->etag); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | // Should throw `FacebookSDKException` exception on HTTP client error. |
@@ -256,49 +256,49 @@ discard block |
||
256 | 256 | |
257 | 257 | $decodedResult = json_decode($result); |
258 | 258 | if ($decodedResult === null) { |
259 | - $out = array(); |
|
260 | - parse_str($result, $out); |
|
261 | - return new FacebookResponse($this, $out, $result, $etagHit, $etagReceived); |
|
259 | + $out = array(); |
|
260 | + parse_str($result, $out); |
|
261 | + return new FacebookResponse($this, $out, $result, $etagHit, $etagReceived); |
|
262 | 262 | } |
263 | 263 | if (isset($decodedResult->error)) { |
264 | - throw FacebookRequestException::create( |
|
264 | + throw FacebookRequestException::create( |
|
265 | 265 | $result, |
266 | 266 | $decodedResult->error, |
267 | 267 | $connection->getResponseHttpStatusCode() |
268 | - ); |
|
268 | + ); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | return new FacebookResponse($this, $decodedResult, $result, $etagHit, $etagReceived); |
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Generate and return the appsecret_proof value for an access_token |
|
276 | - * |
|
277 | - * @param string $token |
|
278 | - * |
|
279 | - * @return string |
|
280 | - */ |
|
281 | - public function getAppSecretProof($token) |
|
282 | - { |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Generate and return the appsecret_proof value for an access_token |
|
276 | + * |
|
277 | + * @param string $token |
|
278 | + * |
|
279 | + * @return string |
|
280 | + */ |
|
281 | + public function getAppSecretProof($token) |
|
282 | + { |
|
283 | 283 | return hash_hmac('sha256', $token, FacebookSession::_getTargetAppSecret()); |
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * appendParamsToUrl - Gracefully appends params to the URL. |
|
288 | - * |
|
289 | - * @param string $url |
|
290 | - * @param array $params |
|
291 | - * |
|
292 | - * @return string |
|
293 | - */ |
|
294 | - public static function appendParamsToUrl($url, $params = array()) |
|
295 | - { |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * appendParamsToUrl - Gracefully appends params to the URL. |
|
288 | + * |
|
289 | + * @param string $url |
|
290 | + * @param array $params |
|
291 | + * |
|
292 | + * @return string |
|
293 | + */ |
|
294 | + public static function appendParamsToUrl($url, $params = array()) |
|
295 | + { |
|
296 | 296 | if (!$params) { |
297 | - return $url; |
|
297 | + return $url; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | if (strpos($url, '?') === false) { |
301 | - return $url . '?' . http_build_query($params, null, '&'); |
|
301 | + return $url . '?' . http_build_query($params, null, '&'); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | list($path, $query_string) = explode('?', $url, 2); |
@@ -308,6 +308,6 @@ discard block |
||
308 | 308 | $params = array_merge($params, $query_array); |
309 | 309 | |
310 | 310 | return $path . '?' . http_build_query($params, null, '&'); |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | 313 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | */ |
214 | 214 | protected function getRequestURL() |
215 | 215 | { |
216 | - return static::BASE_GRAPH_URL . '/' . $this->version . $this->path; |
|
216 | + return static::BASE_GRAPH_URL.'/'.$this->version.$this->path; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | $connection = self::getHttpClientHandler(); |
238 | - $connection->addRequestHeader('User-Agent', 'fb-php-' . self::VERSION); |
|
238 | + $connection->addRequestHeader('User-Agent', 'fb-php-'.self::VERSION); |
|
239 | 239 | $connection->addRequestHeader('Accept-Encoding', '*'); // Support all available encodings. |
240 | 240 | |
241 | 241 | // ETag |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | if (strpos($url, '?') === false) { |
301 | - return $url . '?' . http_build_query($params, null, '&'); |
|
301 | + return $url.'?'.http_build_query($params, null, '&'); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | list($path, $query_string) = explode('?', $url, 2); |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | // Favor params from the original URL over $params |
308 | 308 | $params = array_merge($params, $query_array); |
309 | 309 | |
310 | - return $path . '?' . http_build_query($params, null, '&'); |
|
310 | + return $path.'?'.http_build_query($params, null, '&'); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | } |