1
|
|
|
<?php namespace DarkGold\Salesforce; |
2
|
|
|
|
3
|
|
|
use Carbon\Carbon; |
4
|
|
|
|
5
|
|
|
class AccessTokenGenerator { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Create an access token from stored json data |
9
|
|
|
* |
10
|
|
|
* @param string $text |
11
|
|
|
* @return AccessToken |
12
|
|
|
*/ |
13
|
|
|
public function createFromJson($text) |
14
|
|
|
{ |
15
|
|
|
$savedToken = json_decode($text, true); |
16
|
|
|
|
17
|
|
|
$id = $savedToken['id']; |
18
|
|
|
|
19
|
|
|
$dateIssued = Carbon::parse($savedToken['dateIssued']); |
20
|
|
|
|
21
|
|
|
$dateExpires = Carbon::parse($savedToken['dateExpires']); |
22
|
|
|
|
23
|
|
|
$scope = $savedToken['scope']; |
24
|
|
|
|
25
|
|
|
$tokenType = $savedToken['tokenType']; |
26
|
|
|
|
27
|
|
|
$refreshToken = $savedToken['refreshToken']; |
28
|
|
|
|
29
|
|
|
$signature = $savedToken['signature']; |
30
|
|
|
|
31
|
|
|
$accessToken = $savedToken['accessToken']; |
32
|
|
|
|
33
|
|
|
$apiUrl = $savedToken['apiUrl']; |
34
|
|
|
|
35
|
|
|
$token = new AccessToken( |
36
|
|
|
$id, |
37
|
|
|
$dateIssued, |
38
|
|
|
$dateExpires, |
39
|
|
|
$scope, |
40
|
|
|
$tokenType, |
41
|
|
|
$refreshToken, |
42
|
|
|
$signature, |
43
|
|
|
$accessToken, |
44
|
|
|
$apiUrl |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
return $token; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Create an access token object from the salesforce response data |
52
|
|
|
* |
53
|
|
|
* @param array $salesforceToken |
54
|
|
|
* @return AccessToken |
55
|
|
|
*/ |
56
|
|
|
public function createFromSalesforceResponse(array $salesforceToken) |
57
|
|
|
{ |
58
|
|
|
|
59
|
|
|
$dateIssued = Carbon::createFromTimestamp((int)($salesforceToken['issued_at'] / 1000)); |
60
|
|
|
|
61
|
|
|
$dateExpires = $dateIssued->copy()->addHour()->subMinutes(5); |
62
|
|
|
|
63
|
|
|
$id = $this->getKeyIfSet($salesforceToken, 'id'); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$scope = explode(' ', $this->getKeyIfSet($salesforceToken, 'scope')); |
66
|
|
|
|
67
|
|
|
$refreshToken = $this->getKeyIfSet($salesforceToken, 'refresh_token'); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$signature = $this->getKeyIfSet($salesforceToken, 'signature'); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$tokenType = $this->getKeyIfSet($salesforceToken, 'token_type'); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$accessToken = $salesforceToken['access_token']; |
74
|
|
|
|
75
|
|
|
$apiUrl = $salesforceToken['instance_url']; |
76
|
|
|
|
77
|
|
|
$token = new AccessToken( |
78
|
|
|
$id, |
79
|
|
|
$dateIssued, |
80
|
|
|
$dateExpires, |
81
|
|
|
$scope, |
82
|
|
|
$tokenType, |
83
|
|
|
$refreshToken, |
84
|
|
|
$signature, |
85
|
|
|
$accessToken, |
86
|
|
|
$apiUrl |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
return $token; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param array $array |
94
|
|
|
* @param string $key |
95
|
|
|
* @return null |
96
|
|
|
*/ |
97
|
|
|
private function getKeyIfSet($array, $key) |
98
|
|
|
{ |
99
|
|
|
if (isset($array[$key])) { |
100
|
|
|
return $array[$key]; |
101
|
|
|
} |
102
|
|
|
return null; |
103
|
|
|
} |
104
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.