1 | <?php |
||
7 | final class TokenGenerator implements TokenGeneratorInterface |
||
8 | { |
||
9 | /** |
||
10 | * The key to be used to encrypt the plain token. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | private $key; |
||
15 | |||
16 | /** |
||
17 | * TokenGenerator constructor. |
||
18 | * |
||
19 | * @param string $key The key to be used by the hash algorithm. |
||
20 | */ |
||
21 | 3 | public function __construct($key) |
|
25 | |||
26 | /** |
||
27 | * Generate a new token. |
||
28 | * |
||
29 | * @param int $length The length of the plain text to be generated. |
||
30 | * |
||
31 | * @return GenericToken |
||
32 | */ |
||
33 | 1 | public function generate($length = 6) |
|
39 | |||
40 | /** |
||
41 | * Generate a token from the given plain text. |
||
42 | * |
||
43 | * @param string $plainText The plain text. |
||
44 | * |
||
45 | * @return GenericToken |
||
46 | */ |
||
47 | 1 | public function fromPlain($plainText) |
|
51 | |||
52 | /** |
||
53 | * Generate a token from the given encrypted text. |
||
54 | * |
||
55 | * @param string $encryptedText The encrypted text. |
||
56 | * |
||
57 | * @return GenericToken |
||
58 | */ |
||
59 | 1 | public function fromEncrypted($encryptedText) |
|
63 | |||
64 | /** |
||
65 | * Get the hashed version of the generated token. |
||
66 | * |
||
67 | * @param string $plainText |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 2 | private function encrypt($plainText) |
|
75 | |||
76 | /** |
||
77 | * Create a new token instance with the given parameters. |
||
78 | * |
||
79 | * @param string $encryptedText |
||
80 | * @param string|null $plainText |
||
81 | * |
||
82 | * @return GenericToken |
||
83 | */ |
||
84 | 3 | private function makeToken($encryptedText, $plainText = null) |
|
88 | } |
||
89 |