|
1
|
|
|
<?php namespace Understand\UnderstandLumen; |
|
2
|
|
|
|
|
3
|
|
|
class TokenProvider |
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Current token |
|
8
|
|
|
* |
|
9
|
|
|
* @var type |
|
10
|
|
|
*/ |
|
11
|
|
|
protected $token; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Generate and set new token |
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->generate(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Return token |
|
23
|
|
|
* |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
|
|
public function getToken() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->token; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Generate new token |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function generate() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->token = $this->getUuid(); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Return unique string |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function getUuid() |
|
47
|
|
|
{ |
|
48
|
|
|
// http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid |
|
49
|
|
|
// by Andrew Moore (http://www.php.net/manual/en/function.uniqid.php#94959) |
|
50
|
|
|
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', |
|
51
|
|
|
// 32 bits for "time_low" |
|
|
|
|
|
|
52
|
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), |
|
53
|
|
|
// 16 bits for "time_mid" |
|
|
|
|
|
|
54
|
|
|
mt_rand(0, 0xffff), |
|
55
|
|
|
// 16 bits for "time_hi_and_version", |
|
|
|
|
|
|
56
|
|
|
// four most significant bits holds version number 4 |
|
57
|
|
|
mt_rand(0, 0x0fff) | 0x4000, |
|
58
|
|
|
// 16 bits, 8 bits for "clk_seq_hi_res", |
|
|
|
|
|
|
59
|
|
|
// 8 bits for "clk_seq_low", |
|
|
|
|
|
|
60
|
|
|
// two most significant bits holds zero and one for variant DCE1.1 |
|
61
|
|
|
mt_rand(0, 0x3fff) | 0x8000, |
|
62
|
|
|
// 48 bits for "node" |
|
|
|
|
|
|
63
|
|
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..