|
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
|
|
|
namespace Facebook; |
|
24
|
|
|
|
|
25
|
|
|
use Facebook\Authentication\AccessToken; |
|
26
|
|
|
use Facebook\Exception\SDKException; |
|
27
|
|
|
|
|
28
|
|
|
class Application implements \Serializable |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var string the app ID |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $id; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string the app secret |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $secret; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $id |
|
42
|
|
|
* @param string $secret |
|
43
|
|
|
* |
|
44
|
|
|
* @throws SDKException |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct($id, $secret) |
|
47
|
|
|
{ |
|
48
|
|
|
if (!is_string($id) |
|
49
|
|
|
// Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false |
|
50
|
|
|
&& !is_int($id)) { |
|
51
|
|
|
throw new SDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.'); |
|
52
|
|
|
} |
|
53
|
|
|
// 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 |
|
54
|
|
|
$this->id = (string) $id; |
|
55
|
|
|
$this->secret = $secret; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the app ID. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getId() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->id; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the app secret. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getSecret() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->secret; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns an app access token. |
|
80
|
|
|
* |
|
81
|
|
|
* @return AccessToken |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getAccessToken() |
|
84
|
|
|
{ |
|
85
|
|
|
return new AccessToken($this->id . '|' . $this->secret); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Serializes the Application entity as a string. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function serialize() |
|
94
|
|
|
{ |
|
95
|
|
|
return implode('|', [$this->id, $this->secret]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Unserializes a string as an Application entity. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $serialized |
|
102
|
|
|
*/ |
|
103
|
|
|
public function unserialize($serialized) |
|
104
|
|
|
{ |
|
105
|
|
|
list($id, $secret) = explode('|', $serialized); |
|
106
|
|
|
|
|
107
|
|
|
$this->__construct($id, $secret); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|