|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright 2015 Alexey Maslov <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace alxmsl\Google\OAuth2; |
|
19
|
|
|
|
|
20
|
|
|
use alxmsl\Network\Http\Request; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Abstract Google client class |
|
24
|
|
|
* @author alxmsl |
|
25
|
|
|
* @date 1/13/13 |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract class Client { |
|
28
|
|
|
/** |
|
29
|
|
|
* @var string client identifier |
|
30
|
|
|
*/ |
|
31
|
|
|
private $clientId = ''; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string client secret |
|
35
|
|
|
*/ |
|
36
|
|
|
private $clientSecret = ''; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string redirect uri |
|
40
|
|
|
*/ |
|
41
|
|
|
private $redirectUri = ''; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string access token |
|
45
|
|
|
*/ |
|
46
|
|
|
private $accessToken = ''; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var int connect timeout, seconds |
|
50
|
|
|
*/ |
|
51
|
|
|
private $connectTimeout = 0; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var int request timeout, seconds |
|
55
|
|
|
*/ |
|
56
|
|
|
private $requestTimeout = 0; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Getter for the request |
|
60
|
|
|
* @param string $url request url |
|
61
|
|
|
* @return Request request object |
|
62
|
|
|
*/ |
|
63
|
2 |
|
protected function getRequest($url) { |
|
64
|
2 |
|
$Request = new Request(); |
|
65
|
2 |
|
$Request->setTransport(Request::TRANSPORT_CURL); |
|
66
|
2 |
|
return $Request->setUrl($url) |
|
67
|
2 |
|
->setConnectTimeout($this->getConnectTimeout()) |
|
68
|
2 |
|
->setTimeout($this->getRequestTimeout()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Setter for client identifier |
|
73
|
|
|
* @param string $clientId client identifier |
|
74
|
|
|
* @return Client self |
|
75
|
|
|
*/ |
|
76
|
3 |
|
public function setClientId($clientId) { |
|
77
|
3 |
|
$this->clientId = (string) $clientId; |
|
78
|
3 |
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Getter for client identifier |
|
83
|
|
|
* @return string client identifier |
|
84
|
|
|
*/ |
|
85
|
4 |
|
public function getClientId() { |
|
86
|
4 |
|
return $this->clientId; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Setter for client secret code |
|
91
|
|
|
* @param string $clientSecret client secret code |
|
92
|
|
|
* @return Client self |
|
93
|
|
|
*/ |
|
94
|
2 |
|
public function setClientSecret($clientSecret) { |
|
95
|
2 |
|
$this->clientSecret = (string) $clientSecret; |
|
96
|
2 |
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Getter for client secret code |
|
101
|
|
|
* @return string client secret code |
|
102
|
|
|
*/ |
|
103
|
3 |
|
public function getClientSecret() { |
|
104
|
3 |
|
return $this->clientSecret; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Setter for redirect url |
|
109
|
|
|
* @param string $redirectUri redirect ur; |
|
110
|
|
|
* @return Client self |
|
111
|
|
|
*/ |
|
112
|
3 |
|
public function setRedirectUri($redirectUri) { |
|
113
|
3 |
|
$this->redirectUri = (string) $redirectUri; |
|
114
|
3 |
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Getter for redirect url |
|
119
|
|
|
* @return string redirect url |
|
120
|
|
|
*/ |
|
121
|
4 |
|
public function getRedirectUri() { |
|
122
|
4 |
|
return $this->redirectUri; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Setter for access token value |
|
127
|
|
|
* @param string $accessToken access token value |
|
128
|
|
|
* @return Client self |
|
129
|
|
|
*/ |
|
130
|
4 |
|
public function setAccessToken($accessToken) { |
|
131
|
4 |
|
$this->accessToken = (string) $accessToken; |
|
132
|
4 |
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Getter for access token value |
|
137
|
|
|
* @return string access token value |
|
138
|
|
|
*/ |
|
139
|
7 |
|
public function getAccessToken() { |
|
140
|
7 |
|
return $this->accessToken; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Setter for connect timeout value |
|
145
|
|
|
* @param int $connectTimeout connect timeout, seconds |
|
146
|
|
|
* @return Client self |
|
147
|
|
|
*/ |
|
148
|
2 |
|
public function setConnectTimeout($connectTimeout) { |
|
149
|
2 |
|
$this->connectTimeout = (int) $connectTimeout; |
|
150
|
2 |
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Getter for connect timeout value |
|
155
|
|
|
* @return int connect timeout, seconds |
|
156
|
|
|
*/ |
|
157
|
5 |
|
public function getConnectTimeout() { |
|
158
|
5 |
|
return $this->connectTimeout; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Setter for request timeout value |
|
163
|
|
|
* @param int $requestTimeout request timeout, seconds |
|
164
|
|
|
* @return Client self |
|
165
|
|
|
*/ |
|
166
|
2 |
|
public function setRequestTimeout($requestTimeout) { |
|
167
|
2 |
|
$this->requestTimeout = (int) $requestTimeout; |
|
168
|
2 |
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Getter for request timeout value |
|
173
|
|
|
* @return int request timeout, seconds |
|
174
|
|
|
*/ |
|
175
|
5 |
|
public function getRequestTimeout() { |
|
176
|
5 |
|
return $this->requestTimeout; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|