@@ -33,99 +33,99 @@ discard block |
||
33 | 33 | class SignedRequest |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $rawSignedRequest; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $payload; |
|
45 | - |
|
46 | - /** |
|
47 | - * Instantiate a new SignedRequest entity. |
|
48 | - * |
|
49 | - * @param string|null $rawSignedRequest The raw signed request. |
|
50 | - * @param string|null $state random string to prevent CSRF. |
|
51 | - * @param string|null $appSecret |
|
52 | - */ |
|
53 | - public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | - { |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $rawSignedRequest; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $payload; |
|
45 | + |
|
46 | + /** |
|
47 | + * Instantiate a new SignedRequest entity. |
|
48 | + * |
|
49 | + * @param string|null $rawSignedRequest The raw signed request. |
|
50 | + * @param string|null $state random string to prevent CSRF. |
|
51 | + * @param string|null $appSecret |
|
52 | + */ |
|
53 | + public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | + { |
|
55 | 55 | if (!$rawSignedRequest) { |
56 | - return; |
|
56 | + return; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->rawSignedRequest = $rawSignedRequest; |
60 | 60 | $this->payload = static::parse($rawSignedRequest, $state, $appSecret); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns the raw signed request data. |
|
65 | - * |
|
66 | - * @return string|null |
|
67 | - */ |
|
68 | - public function getRawSignedRequest() |
|
69 | - { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns the raw signed request data. |
|
65 | + * |
|
66 | + * @return string|null |
|
67 | + */ |
|
68 | + public function getRawSignedRequest() |
|
69 | + { |
|
70 | 70 | return $this->rawSignedRequest; |
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the parsed signed request data. |
|
75 | - * |
|
76 | - * @return array|null |
|
77 | - */ |
|
78 | - public function getPayload() |
|
79 | - { |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the parsed signed request data. |
|
75 | + * |
|
76 | + * @return array|null |
|
77 | + */ |
|
78 | + public function getPayload() |
|
79 | + { |
|
80 | 80 | return $this->payload; |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns a property from the signed request data if available. |
|
85 | - * |
|
86 | - * @param string $key |
|
87 | - * @param mixed|null $default |
|
88 | - * |
|
89 | - * @return mixed|null |
|
90 | - */ |
|
91 | - public function get($key, $default = null) |
|
92 | - { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns a property from the signed request data if available. |
|
85 | + * |
|
86 | + * @param string $key |
|
87 | + * @param mixed|null $default |
|
88 | + * |
|
89 | + * @return mixed|null |
|
90 | + */ |
|
91 | + public function get($key, $default = null) |
|
92 | + { |
|
93 | 93 | if (isset($this->payload[$key])) { |
94 | - return $this->payload[$key]; |
|
94 | + return $this->payload[$key]; |
|
95 | 95 | } |
96 | 96 | return $default; |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns user_id from signed request data if available. |
|
101 | - * |
|
102 | - * @return string|null |
|
103 | - */ |
|
104 | - public function getUserId() |
|
105 | - { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns user_id from signed request data if available. |
|
101 | + * |
|
102 | + * @return string|null |
|
103 | + */ |
|
104 | + public function getUserId() |
|
105 | + { |
|
106 | 106 | return $this->get('user_id'); |
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Checks for OAuth data in the payload. |
|
111 | - * |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function hasOAuthData() |
|
115 | - { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Checks for OAuth data in the payload. |
|
111 | + * |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function hasOAuthData() |
|
115 | + { |
|
116 | 116 | return isset($this->payload['oauth_token']) || isset($this->payload['code']); |
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Creates a signed request from an array of data. |
|
121 | - * |
|
122 | - * @param array $payload |
|
123 | - * @param string|null $appSecret |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function make(array $payload, $appSecret = null) |
|
128 | - { |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Creates a signed request from an array of data. |
|
121 | + * |
|
122 | + * @param array $payload |
|
123 | + * @param string|null $appSecret |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function make(array $payload, $appSecret = null) |
|
128 | + { |
|
129 | 129 | $payload['algorithm'] = 'HMAC-SHA256'; |
130 | 130 | $payload['issued_at'] = time(); |
131 | 131 | $encodedPayload = static::base64UrlEncode(json_encode($payload)); |
@@ -134,20 +134,20 @@ discard block |
||
134 | 134 | $encodedSig = static::base64UrlEncode($hashedSig); |
135 | 135 | |
136 | 136 | return $encodedSig.'.'.$encodedPayload; |
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Validates and decodes a signed request and returns |
|
141 | - * the payload as an array. |
|
142 | - * |
|
143 | - * @param string $signedRequest |
|
144 | - * @param string|null $state |
|
145 | - * @param string|null $appSecret |
|
146 | - * |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | - { |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Validates and decodes a signed request and returns |
|
141 | + * the payload as an array. |
|
142 | + * |
|
143 | + * @param string $signedRequest |
|
144 | + * @param string|null $state |
|
145 | + * @param string|null $appSecret |
|
146 | + * |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | + { |
|
151 | 151 | list($encodedSig, $encodedPayload) = static::split($signedRequest); |
152 | 152 | |
153 | 153 | // Signature validation |
@@ -159,228 +159,228 @@ discard block |
||
159 | 159 | $data = static::decodePayload($encodedPayload); |
160 | 160 | static::validateAlgorithm($data); |
161 | 161 | if ($state) { |
162 | - static::validateCsrf($data, $state); |
|
162 | + static::validateCsrf($data, $state); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $data; |
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Validates the format of a signed request. |
|
170 | - * |
|
171 | - * @param string $signedRequest |
|
172 | - * |
|
173 | - * @throws FacebookSDKException |
|
174 | - */ |
|
175 | - public static function validateFormat($signedRequest) |
|
176 | - { |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Validates the format of a signed request. |
|
170 | + * |
|
171 | + * @param string $signedRequest |
|
172 | + * |
|
173 | + * @throws FacebookSDKException |
|
174 | + */ |
|
175 | + public static function validateFormat($signedRequest) |
|
176 | + { |
|
177 | 177 | if (strpos($signedRequest, '.') !== false) { |
178 | - return; |
|
178 | + return; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | throw new FacebookSDKException( |
182 | - 'Malformed signed request.', 606 |
|
182 | + 'Malformed signed request.', 606 |
|
183 | 183 | ); |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Decodes a raw valid signed request. |
|
188 | - * |
|
189 | - * @param string $signedRequest |
|
190 | - * |
|
191 | - * @returns array |
|
192 | - */ |
|
193 | - public static function split($signedRequest) |
|
194 | - { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Decodes a raw valid signed request. |
|
188 | + * |
|
189 | + * @param string $signedRequest |
|
190 | + * |
|
191 | + * @returns array |
|
192 | + */ |
|
193 | + public static function split($signedRequest) |
|
194 | + { |
|
195 | 195 | static::validateFormat($signedRequest); |
196 | 196 | |
197 | 197 | return explode('.', $signedRequest, 2); |
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Decodes the raw signature from a signed request. |
|
202 | - * |
|
203 | - * @param string $encodedSig |
|
204 | - * |
|
205 | - * @returns string |
|
206 | - * |
|
207 | - * @throws FacebookSDKException |
|
208 | - */ |
|
209 | - public static function decodeSignature($encodedSig) |
|
210 | - { |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Decodes the raw signature from a signed request. |
|
202 | + * |
|
203 | + * @param string $encodedSig |
|
204 | + * |
|
205 | + * @returns string |
|
206 | + * |
|
207 | + * @throws FacebookSDKException |
|
208 | + */ |
|
209 | + public static function decodeSignature($encodedSig) |
|
210 | + { |
|
211 | 211 | $sig = static::base64UrlDecode($encodedSig); |
212 | 212 | |
213 | 213 | if ($sig) { |
214 | - return $sig; |
|
214 | + return $sig; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | throw new FacebookSDKException( |
218 | - 'Signed request has malformed encoded signature data.', 607 |
|
218 | + 'Signed request has malformed encoded signature data.', 607 |
|
219 | 219 | ); |
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Decodes the raw payload from a signed request. |
|
224 | - * |
|
225 | - * @param string $encodedPayload |
|
226 | - * |
|
227 | - * @returns array |
|
228 | - * |
|
229 | - * @throws FacebookSDKException |
|
230 | - */ |
|
231 | - public static function decodePayload($encodedPayload) |
|
232 | - { |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Decodes the raw payload from a signed request. |
|
224 | + * |
|
225 | + * @param string $encodedPayload |
|
226 | + * |
|
227 | + * @returns array |
|
228 | + * |
|
229 | + * @throws FacebookSDKException |
|
230 | + */ |
|
231 | + public static function decodePayload($encodedPayload) |
|
232 | + { |
|
233 | 233 | $payload = static::base64UrlDecode($encodedPayload); |
234 | 234 | |
235 | 235 | if ($payload) { |
236 | - $payload = json_decode($payload, true); |
|
236 | + $payload = json_decode($payload, true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | if (is_array($payload)) { |
240 | - return $payload; |
|
240 | + return $payload; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | throw new FacebookSDKException( |
244 | - 'Signed request has malformed encoded payload data.', 607 |
|
244 | + 'Signed request has malformed encoded payload data.', 607 |
|
245 | 245 | ); |
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Validates the algorithm used in a signed request. |
|
250 | - * |
|
251 | - * @param array $data |
|
252 | - * |
|
253 | - * @throws FacebookSDKException |
|
254 | - */ |
|
255 | - public static function validateAlgorithm(array $data) |
|
256 | - { |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Validates the algorithm used in a signed request. |
|
250 | + * |
|
251 | + * @param array $data |
|
252 | + * |
|
253 | + * @throws FacebookSDKException |
|
254 | + */ |
|
255 | + public static function validateAlgorithm(array $data) |
|
256 | + { |
|
257 | 257 | if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') { |
258 | - return; |
|
258 | + return; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | throw new FacebookSDKException( |
262 | - 'Signed request is using the wrong algorithm.', 605 |
|
262 | + 'Signed request is using the wrong algorithm.', 605 |
|
263 | 263 | ); |
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Hashes the signature used in a signed request. |
|
268 | - * |
|
269 | - * @param string $encodedData |
|
270 | - * @param string|null $appSecret |
|
271 | - * |
|
272 | - * @return string |
|
273 | - * |
|
274 | - * @throws FacebookSDKException |
|
275 | - */ |
|
276 | - public static function hashSignature($encodedData, $appSecret = null) |
|
277 | - { |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Hashes the signature used in a signed request. |
|
268 | + * |
|
269 | + * @param string $encodedData |
|
270 | + * @param string|null $appSecret |
|
271 | + * |
|
272 | + * @return string |
|
273 | + * |
|
274 | + * @throws FacebookSDKException |
|
275 | + */ |
|
276 | + public static function hashSignature($encodedData, $appSecret = null) |
|
277 | + { |
|
278 | 278 | $hashedSig = hash_hmac( |
279 | - 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
279 | + 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | if ($hashedSig) { |
283 | - return $hashedSig; |
|
283 | + return $hashedSig; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | throw new FacebookSDKException( |
287 | - 'Unable to hash signature from encoded payload data.', 602 |
|
287 | + 'Unable to hash signature from encoded payload data.', 602 |
|
288 | 288 | ); |
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Validates the signature used in a signed request. |
|
293 | - * |
|
294 | - * @param string $hashedSig |
|
295 | - * @param string $sig |
|
296 | - * |
|
297 | - * @throws FacebookSDKException |
|
298 | - */ |
|
299 | - public static function validateSignature($hashedSig, $sig) |
|
300 | - { |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Validates the signature used in a signed request. |
|
293 | + * |
|
294 | + * @param string $hashedSig |
|
295 | + * @param string $sig |
|
296 | + * |
|
297 | + * @throws FacebookSDKException |
|
298 | + */ |
|
299 | + public static function validateSignature($hashedSig, $sig) |
|
300 | + { |
|
301 | 301 | if (mb_strlen($hashedSig) === mb_strlen($sig)) { |
302 | - $validate = 0; |
|
303 | - for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
302 | + $validate = 0; |
|
303 | + for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
304 | 304 | $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]); |
305 | - } |
|
306 | - if ($validate === 0) { |
|
305 | + } |
|
306 | + if ($validate === 0) { |
|
307 | 307 | return; |
308 | - } |
|
308 | + } |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | throw new FacebookSDKException( |
312 | - 'Signed request has an invalid signature.', 602 |
|
312 | + 'Signed request has an invalid signature.', 602 |
|
313 | 313 | ); |
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Validates a signed request against CSRF. |
|
318 | - * |
|
319 | - * @param array $data |
|
320 | - * @param string $state |
|
321 | - * |
|
322 | - * @throws FacebookSDKException |
|
323 | - */ |
|
324 | - public static function validateCsrf(array $data, $state) |
|
325 | - { |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Validates a signed request against CSRF. |
|
318 | + * |
|
319 | + * @param array $data |
|
320 | + * @param string $state |
|
321 | + * |
|
322 | + * @throws FacebookSDKException |
|
323 | + */ |
|
324 | + public static function validateCsrf(array $data, $state) |
|
325 | + { |
|
326 | 326 | if (isset($data['state']) && $data['state'] === $state) { |
327 | - return; |
|
327 | + return; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | throw new FacebookSDKException( |
331 | - 'Signed request did not pass CSRF validation.', 604 |
|
331 | + 'Signed request did not pass CSRF validation.', 604 |
|
332 | 332 | ); |
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Base64 decoding which replaces characters: |
|
337 | - * + instead of - |
|
338 | - * / instead of _ |
|
339 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | - * |
|
341 | - * @param string $input base64 url encoded input |
|
342 | - * |
|
343 | - * @return string decoded string |
|
344 | - */ |
|
345 | - public static function base64UrlDecode($input) |
|
346 | - { |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Base64 decoding which replaces characters: |
|
337 | + * + instead of - |
|
338 | + * / instead of _ |
|
339 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | + * |
|
341 | + * @param string $input base64 url encoded input |
|
342 | + * |
|
343 | + * @return string decoded string |
|
344 | + */ |
|
345 | + public static function base64UrlDecode($input) |
|
346 | + { |
|
347 | 347 | $urlDecodedBase64 = strtr($input, '-_', '+/'); |
348 | 348 | static::validateBase64($urlDecodedBase64); |
349 | 349 | return base64_decode($urlDecodedBase64); |
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Base64 encoding which replaces characters: |
|
354 | - * + instead of - |
|
355 | - * / instead of _ |
|
356 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | - * |
|
358 | - * @param string $input string to encode |
|
359 | - * |
|
360 | - * @return string base64 url encoded input |
|
361 | - */ |
|
362 | - public static function base64UrlEncode($input) |
|
363 | - { |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Base64 encoding which replaces characters: |
|
354 | + * + instead of - |
|
355 | + * / instead of _ |
|
356 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | + * |
|
358 | + * @param string $input string to encode |
|
359 | + * |
|
360 | + * @return string base64 url encoded input |
|
361 | + */ |
|
362 | + public static function base64UrlEncode($input) |
|
363 | + { |
|
364 | 364 | return strtr(base64_encode($input), '+/', '-_'); |
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Validates a base64 string. |
|
369 | - * |
|
370 | - * @param string $input base64 value to validate |
|
371 | - * |
|
372 | - * @throws FacebookSDKException |
|
373 | - */ |
|
374 | - public static function validateBase64($input) |
|
375 | - { |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Validates a base64 string. |
|
369 | + * |
|
370 | + * @param string $input base64 value to validate |
|
371 | + * |
|
372 | + * @throws FacebookSDKException |
|
373 | + */ |
|
374 | + public static function validateBase64($input) |
|
375 | + { |
|
376 | 376 | $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/'; |
377 | 377 | if (preg_match($pattern, $input)) { |
378 | - return; |
|
378 | + return; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | throw new FacebookSDKException( |
382 | - 'Signed request contains malformed base64 encoding.', 608 |
|
382 | + 'Signed request contains malformed base64 encoding.', 608 |
|
383 | 383 | ); |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | } |
@@ -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 |
@@ -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 | } |
@@ -32,104 +32,104 @@ |
||
32 | 32 | class GraphUser extends GraphObject |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Returns the ID for the user as a string if present. |
|
37 | - * |
|
38 | - * @return string|null |
|
39 | - */ |
|
40 | - public function getId() |
|
41 | - { |
|
35 | + /** |
|
36 | + * Returns the ID for the user as a string if present. |
|
37 | + * |
|
38 | + * @return string|null |
|
39 | + */ |
|
40 | + public function getId() |
|
41 | + { |
|
42 | 42 | return $this->getProperty('id'); |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns the name for the user as a string if present. |
|
47 | - * |
|
48 | - * @return string|null |
|
49 | - */ |
|
50 | - public function getName() |
|
51 | - { |
|
45 | + /** |
|
46 | + * Returns the name for the user as a string if present. |
|
47 | + * |
|
48 | + * @return string|null |
|
49 | + */ |
|
50 | + public function getName() |
|
51 | + { |
|
52 | 52 | return $this->getProperty('name'); |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function getEmail() |
|
56 | - { |
|
55 | + public function getEmail() |
|
56 | + { |
|
57 | 57 | return $this->getProperty('email'); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Returns the first name for the user as a string if present. |
|
62 | - * |
|
63 | - * @return string|null |
|
64 | - */ |
|
65 | - public function getFirstName() |
|
66 | - { |
|
60 | + /** |
|
61 | + * Returns the first name for the user as a string if present. |
|
62 | + * |
|
63 | + * @return string|null |
|
64 | + */ |
|
65 | + public function getFirstName() |
|
66 | + { |
|
67 | 67 | return $this->getProperty('first_name'); |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Returns the middle name for the user as a string if present. |
|
72 | - * |
|
73 | - * @return string|null |
|
74 | - */ |
|
75 | - public function getMiddleName() |
|
76 | - { |
|
70 | + /** |
|
71 | + * Returns the middle name for the user as a string if present. |
|
72 | + * |
|
73 | + * @return string|null |
|
74 | + */ |
|
75 | + public function getMiddleName() |
|
76 | + { |
|
77 | 77 | return $this->getProperty('middle_name'); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Returns the last name for the user as a string if present. |
|
82 | - * |
|
83 | - * @return string|null |
|
84 | - */ |
|
85 | - public function getLastName() |
|
86 | - { |
|
80 | + /** |
|
81 | + * Returns the last name for the user as a string if present. |
|
82 | + * |
|
83 | + * @return string|null |
|
84 | + */ |
|
85 | + public function getLastName() |
|
86 | + { |
|
87 | 87 | return $this->getProperty('last_name'); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Returns the gender for the user as a string if present. |
|
92 | - * |
|
93 | - * @return string|null |
|
94 | - */ |
|
95 | - public function getGender() |
|
96 | - { |
|
90 | + /** |
|
91 | + * Returns the gender for the user as a string if present. |
|
92 | + * |
|
93 | + * @return string|null |
|
94 | + */ |
|
95 | + public function getGender() |
|
96 | + { |
|
97 | 97 | return $this->getProperty('gender'); |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Returns the Facebook URL for the user as a string if available. |
|
102 | - * |
|
103 | - * @return string|null |
|
104 | - */ |
|
105 | - public function getLink() |
|
106 | - { |
|
100 | + /** |
|
101 | + * Returns the Facebook URL for the user as a string if available. |
|
102 | + * |
|
103 | + * @return string|null |
|
104 | + */ |
|
105 | + public function getLink() |
|
106 | + { |
|
107 | 107 | return $this->getProperty('link'); |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Returns the users birthday, if available. |
|
112 | - * |
|
113 | - * @return \DateTime|null |
|
114 | - */ |
|
115 | - public function getBirthday() |
|
116 | - { |
|
110 | + /** |
|
111 | + * Returns the users birthday, if available. |
|
112 | + * |
|
113 | + * @return \DateTime|null |
|
114 | + */ |
|
115 | + public function getBirthday() |
|
116 | + { |
|
117 | 117 | $value = $this->getProperty('birthday'); |
118 | 118 | if ($value) { |
119 | - return new \DateTime($value); |
|
119 | + return new \DateTime($value); |
|
120 | 120 | } |
121 | 121 | return null; |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Returns the current location of the user as a FacebookGraphLocation |
|
126 | - * if available. |
|
127 | - * |
|
128 | - * @return GraphLocation|null |
|
129 | - */ |
|
130 | - public function getLocation() |
|
131 | - { |
|
124 | + /** |
|
125 | + * Returns the current location of the user as a FacebookGraphLocation |
|
126 | + * if available. |
|
127 | + * |
|
128 | + * @return GraphLocation|null |
|
129 | + */ |
|
130 | + public function getLocation() |
|
131 | + { |
|
132 | 132 | return $this->getProperty('location', GraphLocation::className()); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | 135 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | |
31 | 31 | if (version_compare(PHP_VERSION, '5.4.0', '<')) { |
32 | - throw new Exception('The Facebook SDK v4 requires PHP version 5.4 or higher.'); |
|
32 | + throw new Exception('The Facebook SDK v4 requires PHP version 5.4 or higher.'); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -42,29 +42,29 @@ discard block |
||
42 | 42 | */ |
43 | 43 | spl_autoload_register(function ($class) |
44 | 44 | { |
45 | - // project-specific namespace prefix |
|
46 | - $prefix = 'Facebook\\'; |
|
45 | + // project-specific namespace prefix |
|
46 | + $prefix = 'Facebook\\'; |
|
47 | 47 | |
48 | - // base directory for the namespace prefix |
|
49 | - $base_dir = defined('FACEBOOK_SDK_V4_SRC_DIR') ? FACEBOOK_SDK_V4_SRC_DIR : __DIR__ . '/src/Facebook/'; |
|
48 | + // base directory for the namespace prefix |
|
49 | + $base_dir = defined('FACEBOOK_SDK_V4_SRC_DIR') ? FACEBOOK_SDK_V4_SRC_DIR : __DIR__ . '/src/Facebook/'; |
|
50 | 50 | |
51 | - // does the class use the namespace prefix? |
|
52 | - $len = strlen($prefix); |
|
53 | - if (strncmp($prefix, $class, $len) !== 0) { |
|
51 | + // does the class use the namespace prefix? |
|
52 | + $len = strlen($prefix); |
|
53 | + if (strncmp($prefix, $class, $len) !== 0) { |
|
54 | 54 | // no, move to the next registered autoloader |
55 | 55 | return; |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - // get the relative class name |
|
59 | - $relative_class = substr($class, $len); |
|
58 | + // get the relative class name |
|
59 | + $relative_class = substr($class, $len); |
|
60 | 60 | |
61 | - // replace the namespace prefix with the base directory, replace namespace |
|
62 | - // separators with directory separators in the relative class name, append |
|
63 | - // with .php |
|
64 | - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
61 | + // replace the namespace prefix with the base directory, replace namespace |
|
62 | + // separators with directory separators in the relative class name, append |
|
63 | + // with .php |
|
64 | + $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
65 | 65 | |
66 | - // if the file exists, require it |
|
67 | - if (file_exists($file)) { |
|
66 | + // if the file exists, require it |
|
67 | + if (file_exists($file)) { |
|
68 | 68 | require $file; |
69 | - } |
|
69 | + } |
|
70 | 70 | }); |
71 | 71 | \ No newline at end of file |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /* For licensing terms, see /license.txt */ |
3 | 3 | /** |
4 | - * This script executes the importation of all users in the LDAP repository |
|
5 | - * into Chamilo |
|
6 | - * @package chamilo.auth.ldap |
|
7 | - */ |
|
4 | + * This script executes the importation of all users in the LDAP repository |
|
5 | + * into Chamilo |
|
6 | + * @package chamilo.auth.ldap |
|
7 | + */ |
|
8 | 8 | /** |
9 | - * Init |
|
10 | - */ |
|
9 | + * Init |
|
10 | + */ |
|
11 | 11 | if (PHP_SAPI != 'cli') { |
12 | 12 | die ('For security reasons, this script can only be launched from cron or from the command line'); |
13 | 13 | } |
@@ -8,9 +8,9 @@ discard block |
||
8 | 8 | * @package chamilo.auth.ldap |
9 | 9 | */ |
10 | 10 | /** |
11 | - * when a user does not exist yet in dokeos, |
|
12 | - * but he or she does exist in the LDAP, |
|
13 | - * we add him to the dokeos database |
|
11 | + * when a user does not exist yet in dokeos, |
|
12 | + * but he or she does exist in the LDAP, |
|
13 | + * we add him to the dokeos database |
|
14 | 14 | */ |
15 | 15 | //require_once('../../inc/global.inc.php'); - this script should be loaded by the /index.php script anyway, so global is already loaded |
16 | 16 | require_once('authldap.php'); |
@@ -21,17 +21,17 @@ discard block |
||
21 | 21 | |
22 | 22 | if ($ldap_login_success) |
23 | 23 | { |
24 | - //error_log('Found user '.$login.' on LDAP server',0); |
|
25 | - /* |
|
24 | + //error_log('Found user '.$login.' on LDAP server',0); |
|
25 | + /* |
|
26 | 26 | In here, we know that |
27 | 27 | - the user does not exist in dokeos |
28 | 28 | - the users login and password are correct |
29 | 29 | */ |
30 | - $info_array = ldap_find_user_info($login); |
|
31 | - ldap_put_user_info_locally($login, $info_array); |
|
30 | + $info_array = ldap_find_user_info($login); |
|
31 | + ldap_put_user_info_locally($login, $info_array); |
|
32 | 32 | } else { |
33 | 33 | //error_log('Could not find '.$login.' on LDAP server',0); |
34 | - $loginFailed = true; |
|
35 | - unset($_user['user_id']); |
|
36 | - $uidReset = false; |
|
34 | + $loginFailed = true; |
|
35 | + unset($_user['user_id']); |
|
36 | + $uidReset = false; |
|
37 | 37 | } |