1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Beñat Espiña <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BenatEspina\StackExchangeApiClient\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The access token model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class AccessToken implements Model |
20
|
|
|
{ |
21
|
|
|
protected $accessToken; |
22
|
|
|
protected $accountId; |
23
|
|
|
protected $expiresOnDate; |
24
|
|
|
protected $scope; |
25
|
|
|
|
26
|
|
|
public static function fromProperties( |
27
|
|
|
$accessToken, |
28
|
|
|
$accountId, |
29
|
|
|
\DateTimeInterface $expiresOnDate = null, |
30
|
|
|
array $scope = null |
31
|
|
|
) { |
32
|
|
|
$instance = new self(); |
33
|
|
|
$instance |
34
|
|
|
->setAccessToken($accessToken) |
35
|
|
|
->setAccountId($accountId) |
36
|
|
|
->setExpiresOnDate($expiresOnDate) |
37
|
|
|
->setScope($scope); |
38
|
|
|
|
39
|
|
|
return $instance; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function fromJson(array $data) |
43
|
|
|
{ |
44
|
|
|
$instance = new self(); |
45
|
|
|
$instance |
46
|
|
|
->setAccessToken(array_key_exists('access_token', $data) ? $data['access_token'] : null) |
47
|
|
|
->setAccountId(array_key_exists('account_id', $data) ? $data['account_id'] : null) |
48
|
|
|
->setExpiresOnDate( |
49
|
|
|
array_key_exists('expires_on_date', $data) |
50
|
|
|
? new \DateTimeImmutable('@' . $data['expires_on_date']) |
51
|
|
|
: null |
52
|
|
|
) |
53
|
|
|
->setScope(array_key_exists('scope', $data) ? $data['scope'] : null); |
54
|
|
|
|
55
|
|
|
return $instance; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function setAccessToken($accessToken) |
59
|
|
|
{ |
60
|
|
|
$this->accessToken = $accessToken; |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getAccessToken() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
return $this->accessToken; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setAccountId($accountId) |
71
|
|
|
{ |
72
|
|
|
$this->accountId = $accountId; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getAccountId() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
return $this->accountId; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setExpiresOnDate(\DateTimeInterface $expiresOnDate = null) |
83
|
|
|
{ |
84
|
|
|
$this->expiresOnDate = $expiresOnDate; |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getExpiresOnDate() |
90
|
|
|
{ |
91
|
|
|
return $this->expiresOnDate; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setScope(array $scope = null) |
95
|
|
|
{ |
96
|
|
|
$this->scope = $scope; |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getScope() |
102
|
|
|
{ |
103
|
|
|
return $this->scope; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.