1 | <?php |
||
17 | class Token implements TokenInterface |
||
18 | { |
||
19 | /** |
||
20 | * The attributes of the token. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | public $attributes = [ |
||
25 | 'authenticable_id' => null, |
||
26 | 'plain_text' => null, |
||
27 | 'expiry_time' => null, |
||
28 | 'cipher_text' => null, |
||
29 | 'created_at' => null, |
||
30 | 'updated_at' => null, |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * Token constructor. |
||
35 | * |
||
36 | * @param int|mixed|string $authenticableId |
||
37 | * @param string $cipherText |
||
38 | * @param null|string $plainText |
||
39 | * @param null|int $expiryTime |
||
40 | * @param null|Carbon $createdAt |
||
41 | * @param null|Carbon $updatedAt |
||
42 | */ |
||
43 | 20 | public function __construct( |
|
66 | |||
67 | /** |
||
68 | * Convert the token to string. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | 2 | public function __toString(): string |
|
76 | |||
77 | /** |
||
78 | * Get the unique identifier of the authenticable |
||
79 | * who owns the token. |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | 7 | public function authenticableId() |
|
87 | |||
88 | /** |
||
89 | * Get the token as cipher text. |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 8 | public function cipherText(): string |
|
97 | |||
98 | /** |
||
99 | * Get the token as plain text. |
||
100 | * |
||
101 | * @return null|string |
||
102 | */ |
||
103 | 1 | public function plainText(): ?string |
|
107 | |||
108 | /** |
||
109 | * Get the date token created. |
||
110 | * |
||
111 | * @return Carbon |
||
112 | */ |
||
113 | 4 | public function createdAt(): Carbon |
|
117 | |||
118 | /** |
||
119 | * Get the last update date of the token. |
||
120 | * |
||
121 | * @return Carbon |
||
122 | */ |
||
123 | 2 | public function updatedAt(): Carbon |
|
127 | |||
128 | /** |
||
129 | * Get the expiry time of the token in seconds. |
||
130 | * |
||
131 | * @return int |
||
132 | */ |
||
133 | 8 | public function expiryTime(): int |
|
137 | |||
138 | /** |
||
139 | * Get the date time the token will expire. |
||
140 | * |
||
141 | * @return Carbon |
||
142 | */ |
||
143 | 3 | public function expiresAt(): Carbon |
|
147 | |||
148 | /** |
||
149 | * Get the validity time left for the token. |
||
150 | * |
||
151 | * @return int |
||
152 | */ |
||
153 | 2 | public function timeLeft(): int |
|
157 | |||
158 | /** |
||
159 | * Determine if the token is expired or not. |
||
160 | * |
||
161 | * @return bool |
||
162 | */ |
||
163 | 1 | public function expired(): bool |
|
167 | |||
168 | /** |
||
169 | * Alias for invalidate. |
||
170 | */ |
||
171 | 1 | public function revoke(): void |
|
175 | |||
176 | /** |
||
177 | * Invalidate the token. |
||
178 | */ |
||
179 | 2 | public function invalidate(): void |
|
185 | |||
186 | /** |
||
187 | * Extend the validity of the token. |
||
188 | * |
||
189 | * @param null|int $seconds |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | 2 | public function extend(?int $seconds = null): bool |
|
201 | |||
202 | /** |
||
203 | * Refresh the token. |
||
204 | * |
||
205 | * @return bool |
||
206 | */ |
||
207 | 1 | public function refresh(): bool |
|
213 | |||
214 | /** |
||
215 | * Create a new token. |
||
216 | * |
||
217 | * @param $authenticableId |
||
218 | * @param string $cipherText |
||
219 | * @param null|string $plainText |
||
220 | * |
||
221 | * @return TokenInterface |
||
222 | */ |
||
223 | 2 | public static function create( |
|
234 | |||
235 | /** |
||
236 | * Retrieve a token by the given attributes from the storage. |
||
237 | * |
||
238 | * @param array $attributes |
||
239 | * |
||
240 | * @return null|TokenInterface |
||
241 | */ |
||
242 | 2 | public static function retrieveByAttributes(array $attributes): ?TokenInterface |
|
263 | |||
264 | /** |
||
265 | * Convert the token to a token notification. |
||
266 | * |
||
267 | * @return Notification |
||
268 | */ |
||
269 | 1 | public function toNotification(): Notification |
|
273 | |||
274 | /** |
||
275 | * Persist the token in the storage. |
||
276 | * |
||
277 | * @return bool |
||
278 | */ |
||
279 | 6 | protected function persist(): bool |
|
311 | |||
312 | /** |
||
313 | * Get the date time at the moment. |
||
314 | * |
||
315 | * @return Carbon |
||
316 | */ |
||
317 | 20 | private function getNow(): Carbon |
|
321 | |||
322 | /** |
||
323 | * Get the name of the table token will be persisted. |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | 8 | private static function getTable(): string |
|
331 | |||
332 | /** |
||
333 | * Get the default expiry time in seconds. |
||
334 | * |
||
335 | * @return int |
||
336 | */ |
||
337 | 2 | private function getDefaultExpiryTime(): int |
|
341 | } |
||
342 |