TheRakeshPurohit /
rtCamp
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright 2017 Facebook, Inc. |
||
| 4 | * |
||
| 5 | * You are hereby granted a non-exclusive, worldwide, royalty-free license to |
||
| 6 | * use, copy, modify, and distribute this software in source code or binary |
||
| 7 | * form for use in connection with the web services and APIs provided by |
||
| 8 | * Facebook. |
||
| 9 | * |
||
| 10 | * As with any software that integrates with the Facebook platform, your use |
||
| 11 | * of this software is subject to the Facebook Developer Principles and |
||
| 12 | * Policies [http://developers.facebook.com/policy/]. This copyright notice |
||
| 13 | * shall be included in all copies or substantial portions of the software. |
||
| 14 | * |
||
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
| 21 | * DEALINGS IN THE SOFTWARE. |
||
| 22 | * |
||
| 23 | */ |
||
| 24 | namespace Facebook; |
||
| 25 | |||
| 26 | use Facebook\Authentication\AccessToken; |
||
| 27 | use Facebook\Exceptions\FacebookSDKException; |
||
| 28 | |||
| 29 | class FacebookApp implements \Serializable |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @var string The app ID. |
||
| 33 | */ |
||
| 34 | protected $id; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string The app secret. |
||
| 38 | */ |
||
| 39 | protected $secret; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param string $id |
||
| 43 | * @param string $secret |
||
| 44 | * |
||
| 45 | * @throws FacebookSDKException |
||
| 46 | */ |
||
| 47 | public function __construct($id, $secret) |
||
| 48 | { |
||
| 49 | if (!is_string($id) |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 50 | // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false |
||
| 51 | && !is_int($id)) { |
||
| 52 | throw new FacebookSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.'); |
||
| 53 | } |
||
| 54 | // We cast as a string in case a valid int was set on a 64-bit system and this is unserialised on a 32-bit system |
||
| 55 | $this->id = (string) $id; |
||
| 56 | $this->secret = $secret; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Returns the app ID. |
||
| 61 | * |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | public function getId() |
||
| 65 | { |
||
| 66 | return $this->id; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Returns the app secret. |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | public function getSecret() |
||
| 75 | { |
||
| 76 | return $this->secret; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Returns an app access token. |
||
| 81 | * |
||
| 82 | * @return AccessToken |
||
| 83 | */ |
||
| 84 | public function getAccessToken() |
||
| 85 | { |
||
| 86 | return new AccessToken($this->id . '|' . $this->secret); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Serializes the FacebookApp entity as a string. |
||
| 91 | * |
||
| 92 | * @return string |
||
| 93 | */ |
||
| 94 | public function serialize() |
||
| 95 | { |
||
| 96 | return implode('|', [$this->id, $this->secret]); |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Unserializes a string as a FacebookApp entity. |
||
| 101 | * |
||
| 102 | * @param string $serialized |
||
| 103 | */ |
||
| 104 | public function unserialize($serialized) |
||
| 105 | { |
||
| 106 | list($id, $secret) = explode('|', $serialized); |
||
| 107 | |||
| 108 | $this->__construct($id, $secret); |
||
| 109 | } |
||
| 110 | } |
||
| 111 |