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
|
6 |
|
* @ManyToOne(targetEntity="OAuth\Client") |
61
|
|
|
* @JoinColumn(name="client", referencedColumnName="id") |
62
|
6 |
|
*/ |
63
|
6 |
|
private $client; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var User |
67
|
|
|
* @ManyToOne(targetEntity="OAuth\User") |
68
|
1 |
|
* @JoinColumn(name="user", referencedColumnName="id") |
69
|
|
|
*/ |
70
|
1 |
|
private $user; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get id |
74
|
|
|
* |
75
|
|
|
* @return integer |
76
|
1 |
|
*/ |
77
|
|
|
public function getId() |
78
|
1 |
|
{ |
79
|
1 |
|
return $this->id; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set code |
84
|
|
|
* |
85
|
1 |
|
* @param string $code |
86
|
|
|
* @return AuthCode |
87
|
1 |
|
*/ |
88
|
1 |
|
public function setCode($code) |
89
|
|
|
{ |
90
|
|
|
$this->code = $code; |
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get code |
96
|
1 |
|
* |
97
|
|
|
* @return string |
98
|
1 |
|
*/ |
99
|
|
|
public function getCode() |
100
|
|
|
{ |
101
|
|
|
return $this->code; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Set client_id |
106
|
1 |
|
* |
107
|
|
|
* @param int $clientId |
108
|
1 |
|
* @return AuthCode |
109
|
|
|
*/ |
110
|
|
|
public function setClientId($clientId) |
111
|
|
|
{ |
112
|
|
|
$this->clientId = $clientId; |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
1 |
|
/** |
117
|
|
|
* Get client_id |
118
|
1 |
|
* |
119
|
1 |
|
* @return int |
120
|
|
|
*/ |
121
|
|
|
public function getClientId() |
122
|
|
|
{ |
123
|
|
|
return $this->clientId; |
124
|
|
|
} |
125
|
|
|
|
126
|
1 |
|
/** |
127
|
|
|
* Set user_id |
128
|
1 |
|
* |
129
|
1 |
|
* @param string $userId |
130
|
|
|
* @return AuthCode |
131
|
|
|
*/ |
132
|
|
|
public function setUserId($userId) |
133
|
|
|
{ |
134
|
|
|
$this->userId = $userId; |
135
|
|
|
return $this; |
136
|
1 |
|
} |
137
|
|
|
|
138
|
1 |
|
/** |
139
|
|
|
* Get user_identifier |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getUserId() |
144
|
|
|
{ |
145
|
|
|
return $this->userId; |
146
|
1 |
|
} |
147
|
|
|
|
148
|
1 |
|
/** |
149
|
|
|
* Set expires |
150
|
|
|
* |
151
|
|
|
* @param \DateTime $expires |
152
|
|
|
* @return AuthCode |
153
|
|
|
*/ |
154
|
|
|
public function setExpires($expires) |
155
|
|
|
{ |
156
|
1 |
|
$this->expires = $expires; |
157
|
|
|
return $this; |
158
|
1 |
|
} |
159
|
1 |
|
|
160
|
|
|
/** |
161
|
|
|
* Get expires |
162
|
|
|
* |
163
|
|
|
* @return \DateTime |
164
|
1 |
|
*/ |
165
|
|
|
public function getExpires() |
166
|
1 |
|
{ |
167
|
|
|
return $this->expires; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Set redirect_uri |
172
|
1 |
|
* |
173
|
|
|
* @param string $redirectUri |
174
|
1 |
|
* @return AuthCode |
175
|
1 |
|
*/ |
176
|
|
|
public function setRedirectUri($redirectUri) |
177
|
|
|
{ |
178
|
|
|
$this->redirectUri = $redirectUri; |
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get redirect_uri |
184
|
|
|
* |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
|
|
public function getRedirectUri() |
188
|
|
|
{ |
189
|
|
|
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
|
|
|
$code = new self(); |
279
|
|
|
foreach ($params as $property => $value) { |
280
|
|
|
$code->$property = $value; |
281
|
|
|
} |
282
|
|
|
return $code; |
283
|
|
|
} |
284
|
|
|
} |