1 | <?php |
||
7 | class Recovery |
||
8 | { |
||
9 | protected $codes = []; |
||
10 | |||
11 | protected $count = 8; |
||
12 | |||
13 | protected $blocks = 2; |
||
14 | |||
15 | protected $chars = 10; |
||
16 | |||
17 | protected $random; |
||
18 | |||
19 | protected $blockSeparator = '-'; |
||
20 | |||
21 | private $collectionFunction = 'collect'; |
||
22 | |||
23 | /** |
||
24 | * Recovery constructor. |
||
25 | * |
||
26 | * @param Random $random |
||
27 | */ |
||
28 | 11 | public function __construct(Random $random = null) |
|
36 | |||
37 | /** |
||
38 | * Set to alpha codes. |
||
39 | * |
||
40 | * @return Recovery |
||
41 | */ |
||
42 | 1 | public function alpha() |
|
48 | |||
49 | /** |
||
50 | * Generate the recovery codes. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 10 | protected function generate() |
|
64 | |||
65 | /** |
||
66 | * Generate all blocks. |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | 10 | protected function generateBlocks() |
|
80 | |||
81 | /** |
||
82 | * Generate random chars. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 10 | protected function generateChars() |
|
90 | |||
91 | /** |
||
92 | * Check if codes must be generated. |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 10 | protected function mustGenerate() |
|
100 | |||
101 | /** |
||
102 | * Set lowercase codes state. |
||
103 | * |
||
104 | * @param bool $state |
||
105 | * @return Recovery |
||
106 | */ |
||
107 | 1 | public function lowercase($state = true) |
|
113 | |||
114 | /** |
||
115 | * Set the block separator. |
||
116 | * |
||
117 | * @param string $blockSeparator |
||
118 | * @return Recovery |
||
119 | */ |
||
120 | 1 | public function setBlockSeparator($blockSeparator) |
|
126 | |||
127 | /** |
||
128 | * Set the collection function. |
||
129 | * |
||
130 | * @param string $collectionFunction |
||
131 | * @return Recovery |
||
132 | */ |
||
133 | 1 | public function collectionFunction($collectionFunction) |
|
139 | |||
140 | /** |
||
141 | * Set uppercase codes state. |
||
142 | * |
||
143 | * @param bool $state |
||
144 | * @return Recovery |
||
145 | */ |
||
146 | 1 | public function uppercase($state = true) |
|
152 | |||
153 | /** |
||
154 | * Set mixedcase codes state. |
||
155 | * |
||
156 | * @return Recovery |
||
157 | */ |
||
158 | 1 | public function mixedcase() |
|
164 | |||
165 | /** |
||
166 | * Set to numeric codes. |
||
167 | * |
||
168 | * @return Recovery |
||
169 | */ |
||
170 | 1 | public function numeric() |
|
176 | |||
177 | /** |
||
178 | * Get an array of recovery codes. |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | 10 | public function toArray() |
|
190 | |||
191 | /** |
||
192 | * Get a collection of recovery codes. |
||
193 | * |
||
194 | * @return array |
||
195 | * @throws \Exception |
||
196 | */ |
||
197 | 2 | public function toCollection() |
|
205 | |||
206 | /** |
||
207 | * Get a json of recovery codes. |
||
208 | * |
||
209 | * @return array |
||
210 | */ |
||
211 | 1 | public function toJson() |
|
215 | |||
216 | /** |
||
217 | * Get the blocks size. |
||
218 | * |
||
219 | * @return int |
||
220 | */ |
||
221 | 10 | public function getBlocks() |
|
225 | |||
226 | /** |
||
227 | * Get the chars count. |
||
228 | * |
||
229 | * @return int |
||
230 | */ |
||
231 | 10 | public function getChars() |
|
235 | |||
236 | /** |
||
237 | * Get the codes. |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | 1 | public function getCodes() |
|
245 | |||
246 | /** |
||
247 | * Get the codes count. |
||
248 | * |
||
249 | * @return int |
||
250 | */ |
||
251 | 10 | public function getCount() |
|
255 | |||
256 | /** |
||
257 | * Reset generated codes. |
||
258 | * |
||
259 | */ |
||
260 | 10 | protected function reset() |
|
264 | |||
265 | /** |
||
266 | * Set the blocks size. |
||
267 | * |
||
268 | * @param int $blocks |
||
269 | * @return Recovery |
||
270 | */ |
||
271 | 5 | public function setBlocks($blocks) |
|
279 | |||
280 | /** |
||
281 | * Set the chars count. |
||
282 | * |
||
283 | * @param int $chars |
||
284 | * @return Recovery |
||
285 | */ |
||
286 | 4 | public function setChars($chars) |
|
294 | |||
295 | /** |
||
296 | * Set the codes count. |
||
297 | * |
||
298 | * @param int $count |
||
299 | * @return Recovery |
||
300 | */ |
||
301 | 6 | public function setCount($count) |
|
309 | } |
||
310 |