|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maztech; |
|
4
|
|
|
|
|
5
|
|
|
use Maztech\Authentication\AccessToken; |
|
6
|
|
|
// use Maztech\Exceptions\InstagramSDKException; |
|
7
|
|
|
|
|
8
|
|
|
class InstagramApp implements \Serializable |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string The app ID. |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $id; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string The app secret. |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $secret; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param string $id |
|
22
|
|
|
* @param string $secret |
|
23
|
|
|
* |
|
24
|
|
|
* @throws InstagramSDKException |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct($id, $secret) |
|
27
|
|
|
{ |
|
28
|
|
|
// if (!is_string($id) |
|
29
|
|
|
// // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false |
|
30
|
|
|
// && !is_int($id)) { |
|
31
|
|
|
// throw new InstagramSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.'); |
|
32
|
|
|
// } |
|
33
|
|
|
// 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 |
|
34
|
|
|
$this->id = (string) $id; |
|
35
|
|
|
$this->secret = $secret; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Returns the app ID. |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getId() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->id; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Returns the app secret. |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getSecret() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->secret; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns an app access token. |
|
60
|
|
|
* |
|
61
|
|
|
* @return AccessToken |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getAccessToken() |
|
64
|
|
|
{ |
|
65
|
|
|
return new AccessToken($this->id . '|' . $this->secret); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Serializes the InstagramApp entity as a string. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function serialize() |
|
74
|
|
|
{ |
|
75
|
|
|
return implode('|', [$this->id, $this->secret]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Unserializes a string as a InstagramApp entity. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $serialized |
|
82
|
|
|
*/ |
|
83
|
|
|
public function unserialize($serialized) |
|
84
|
|
|
{ |
|
85
|
|
|
list($id, $secret) = explode('|', $serialized); |
|
86
|
|
|
|
|
87
|
|
|
$this->__construct($id, $secret); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|