1 | <?php |
||
5 | class Recovery |
||
6 | { |
||
7 | protected $codes = []; |
||
8 | |||
9 | protected $count = 8; |
||
10 | |||
11 | protected $blocks = 2; |
||
12 | |||
13 | protected $chars = 10; |
||
14 | |||
15 | protected $random; |
||
16 | |||
17 | protected $blockSeparator = '-'; |
||
18 | |||
19 | /** |
||
20 | * Recovery constructor. |
||
21 | * |
||
22 | * @param Random $random |
||
23 | */ |
||
24 | 9 | public function __construct(Random $random = null) |
|
32 | |||
33 | /** |
||
34 | * Generate the recovery codes. |
||
35 | * |
||
36 | * @return array |
||
37 | */ |
||
38 | 9 | protected function generate() |
|
48 | |||
49 | /** |
||
50 | * Generate all blocks. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 9 | protected function generateBlocks() |
|
64 | |||
65 | /** |
||
66 | * Generate random chars. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | 9 | protected function generateChars() |
|
74 | |||
75 | /** |
||
76 | * Check if codes must be generated. |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 9 | protected function mustGenerate() |
|
84 | |||
85 | /** |
||
86 | * Set lowercase codes state. |
||
87 | * |
||
88 | * @param bool $state |
||
89 | * @return Recovery |
||
90 | */ |
||
91 | 1 | public function lowercase($state = true) |
|
97 | |||
98 | /** |
||
99 | * Set the block separator. |
||
100 | * |
||
101 | * @param string $blockSeparator |
||
102 | * @return Recovery |
||
103 | */ |
||
104 | 1 | public function setBlockSeparator($blockSeparator) |
|
110 | |||
111 | /** |
||
112 | * Set uppercase codes state. |
||
113 | * |
||
114 | * @param bool $state |
||
115 | * @return Recovery |
||
116 | */ |
||
117 | 1 | public function uppercase($state = true) |
|
123 | |||
124 | /** |
||
125 | * Set mixedcase codes state. |
||
126 | * |
||
127 | * @return Recovery |
||
128 | */ |
||
129 | 1 | public function mixedcase() |
|
135 | |||
136 | /** |
||
137 | * Set to numeric codes. |
||
138 | * |
||
139 | * @return Recovery |
||
140 | */ |
||
141 | 1 | public function numeric() |
|
147 | |||
148 | /** |
||
149 | * Set to alpha codes. |
||
150 | * |
||
151 | * @return Recovery |
||
152 | */ |
||
153 | 1 | public function alpha() |
|
159 | |||
160 | /** |
||
161 | * Get an array of recovery codes. |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 9 | public function toArray() |
|
173 | |||
174 | /** |
||
175 | * Get a json of recovery codes. |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | 1 | public function toJson() |
|
183 | |||
184 | /** |
||
185 | * Get the blocks size. |
||
186 | * |
||
187 | * @return int |
||
188 | */ |
||
189 | 9 | public function getBlocks() |
|
193 | |||
194 | /** |
||
195 | * Get the chars count. |
||
196 | * |
||
197 | * @return int |
||
198 | */ |
||
199 | 9 | public function getChars() |
|
203 | |||
204 | /** |
||
205 | * Get the codes. |
||
206 | * |
||
207 | * @return array |
||
208 | */ |
||
209 | 1 | public function getCodes() |
|
213 | |||
214 | /** |
||
215 | * Get the codes count. |
||
216 | * |
||
217 | * @return int |
||
218 | */ |
||
219 | 9 | public function getCount() |
|
223 | |||
224 | /** |
||
225 | * Reset generated codes. |
||
226 | * |
||
227 | */ |
||
228 | 9 | protected function reset() |
|
232 | |||
233 | /** |
||
234 | * Set the blocks size. |
||
235 | * |
||
236 | * @param int $blocks |
||
237 | * @return Recovery |
||
238 | */ |
||
239 | 5 | public function setBlocks($blocks) |
|
247 | |||
248 | /** |
||
249 | * Set the chars count. |
||
250 | * |
||
251 | * @param int $chars |
||
252 | * @return Recovery |
||
253 | */ |
||
254 | 4 | public function setChars($chars) |
|
262 | |||
263 | /** |
||
264 | * Set the codes count. |
||
265 | * |
||
266 | * @param int $count |
||
267 | * @return Recovery |
||
268 | */ |
||
269 | 6 | public function setCount($count) |
|
277 | } |
||
278 |