1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @Entity(repositoryClass="OAuth\Repository\AuthCodeRepository") |
9
|
|
|
* @Table(name="AuthCode",uniqueConstraints={@UniqueConstraint(name="code_idx", columns={"code"})}) |
10
|
|
|
*/ |
11
|
|
|
class AuthCode |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var integer |
16
|
|
|
* @Id |
17
|
|
|
* @Column(type="integer", length=11) |
18
|
|
|
* @GeneratedValue |
19
|
|
|
*/ |
20
|
|
|
private $id; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
* @Column(type="string",length=40) |
25
|
|
|
*/ |
26
|
|
|
private $code; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
* @Column(type="integer",length=11) |
31
|
|
|
*/ |
32
|
|
|
private $clientId; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
* @Column(type="integer",length=11, nullable=true) |
37
|
|
|
*/ |
38
|
|
|
private $userId; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var DateTime |
42
|
|
|
* @Column(type="datetime") |
43
|
|
|
*/ |
44
|
|
|
private $expires; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
* @Column(type="string",length=255) |
49
|
|
|
*/ |
50
|
|
|
private $redirectUri; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
* @Column(type="string",length=50) |
55
|
|
|
*/ |
56
|
|
|
private $scope; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var Client |
60
|
|
|
* @ManyToOne(targetEntity="OAuth\Client") |
61
|
|
|
* @JoinColumn(name="client", referencedColumnName="id") |
62
|
|
|
*/ |
63
|
|
|
private $client; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var User |
67
|
|
|
* @ManyToOne(targetEntity="OAuth\User") |
68
|
|
|
* @JoinColumn(name="user", referencedColumnName="id") |
69
|
|
|
*/ |
70
|
|
|
private $user; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get id |
74
|
|
|
* |
75
|
|
|
* @return integer |
76
|
|
|
*/ |
77
|
|
|
public function getId() |
78
|
|
|
{ |
79
|
|
|
return $this->id; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set code |
84
|
|
|
* |
85
|
|
|
* @param string $code |
86
|
|
|
* @return AuthCode |
87
|
|
|
*/ |
88
|
|
|
public function setCode($code) |
89
|
|
|
{ |
90
|
|
|
$this->code = $code; |
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get code |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getCode() |
100
|
|
|
{ |
101
|
|
|
return $this->code; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Set client_id |
106
|
|
|
* |
107
|
|
|
* @param int $clientId |
108
|
|
|
* @return AuthCode |
109
|
|
|
*/ |
110
|
|
|
public function setClientId($clientId) |
111
|
|
|
{ |
112
|
|
|
$this->clientId = $clientId; |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get client_id |
118
|
|
|
* |
119
|
|
|
* @return int |
120
|
|
|
*/ |
121
|
|
|
public function getClientId() |
122
|
|
|
{ |
123
|
|
|
return $this->clientId; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Set user_id |
128
|
|
|
* |
129
|
|
|
* @param string $userId |
130
|
|
|
* @return AuthCode |
131
|
|
|
*/ |
132
|
|
|
public function setUserId($userId) |
133
|
|
|
{ |
134
|
|
|
$this->userId = $userId; |
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get user_identifier |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getUserId() |
144
|
|
|
{ |
145
|
|
|
return $this->userId; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set expires |
150
|
|
|
* |
151
|
|
|
* @param \DateTime $expires |
152
|
|
|
* @return AuthCode |
153
|
|
|
*/ |
154
|
|
|
public function setExpires($expires) |
155
|
|
|
{ |
156
|
|
|
$this->expires = $expires; |
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get expires |
162
|
|
|
* |
163
|
|
|
* @return \DateTime |
164
|
|
|
*/ |
165
|
|
|
public function getExpires() |
166
|
|
|
{ |
167
|
|
|
return $this->expires; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Set redirect_uri |
172
|
|
|
* |
173
|
|
|
* @param string $redirectUri |
174
|
|
|
* @return AuthCode |
175
|
|
|
*/ |
176
|
1 |
|
public function setRedirectUri($redirectUri) |
177
|
|
|
{ |
178
|
1 |
|
$this->redirectUri = $redirectUri; |
179
|
1 |
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get redirect_uri |
184
|
|
|
* |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
1 |
|
public function getRedirectUri() |
188
|
|
|
{ |
189
|
1 |
|
return $this->redirectUri; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Set scope |
194
|
|
|
* |
195
|
|
|
* @param string $scope |
196
|
|
|
* @return AuthCode |
197
|
|
|
*/ |
198
|
|
|
public function setScope($scope) |
199
|
|
|
{ |
200
|
|
|
$this->scope = $scope; |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get scope |
206
|
|
|
* |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
public function getScope() |
210
|
|
|
{ |
211
|
|
|
return $this->scope; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set client |
216
|
|
|
* |
217
|
|
|
* @param Client $client |
218
|
|
|
* @return AuthCode |
219
|
|
|
*/ |
220
|
|
|
public function setClient(Client $client = null) |
221
|
|
|
{ |
222
|
|
|
$this->client = $client; |
223
|
|
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Get client |
228
|
|
|
* |
229
|
|
|
* @return Client |
230
|
|
|
*/ |
231
|
|
|
public function getClient() |
232
|
|
|
{ |
233
|
|
|
return $this->client; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Set user |
238
|
|
|
* |
239
|
|
|
* @param User $user |
240
|
|
|
* @return AuthCode |
241
|
|
|
*/ |
242
|
|
|
public function setUser(User $user = null) |
243
|
|
|
{ |
244
|
|
|
$this->user = $user; |
245
|
|
|
return $this; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Get user |
250
|
|
|
* |
251
|
|
|
* @return User |
252
|
|
|
*/ |
253
|
|
|
public function getUser() |
254
|
|
|
{ |
255
|
|
|
return $this->user; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return array |
260
|
|
|
*/ |
261
|
|
|
public function toArray() |
262
|
|
|
{ |
263
|
|
|
return [ |
264
|
|
|
'code' => $this->code, |
265
|
|
|
'client_id' => $this->clientId, |
266
|
|
|
'user_id' => $this->userId, |
267
|
|
|
'expires' => $this->expires, |
268
|
|
|
'scope' => $this->scope, |
269
|
|
|
]; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param $params |
274
|
|
|
* @return AuthCode |
275
|
|
|
*/ |
276
|
|
|
public static function fromArray($params) |
277
|
|
|
{ |
278
|
|
|
//die(var_dump($params)); |
|
|
|
|
279
|
|
|
$user = $params['user']; |
280
|
|
|
$userId = ($user instanceof \OAuth\User) ? $user->getId() : null; |
281
|
|
|
$code = new self(); |
282
|
|
|
$code->setCode($params['code']) |
283
|
|
|
->setClient($params['client']) |
284
|
|
|
->setClientId($params['client']->getId()) |
285
|
|
|
->setUser($user) |
286
|
|
|
->setUserId($userId) |
287
|
|
|
->setRedirectUri($params['redirect_uri']) |
288
|
|
|
->setExpires($params['expires']) |
289
|
|
|
->setScope($params['scope']) |
290
|
|
|
; |
291
|
|
|
return $code; |
292
|
|
|
} |
293
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.