31
31
32
32
namespace Jocic \GoogleAuthenticator \Qr \Remote ;
33
33
34
+ use Jocic \Encoders \Base \Base16 ;
34
35
use Jocic \Encoders \Base \Base32 ;
35
36
use Jocic \GoogleAuthenticator \Qr \QrInterface ;
36
37
use Jocic \GoogleAuthenticator \Account ;
@@ -50,7 +51,23 @@ class GoogleQr implements QrInterface, RemoteQrInterface
50
51
|* CORE CONSTANTS *|
51
52
\******************/
52
53
53
- // CORE CONSTANTS GO HERE
54
+ /**
55
+ * Encoding constant - for getting QR code image in <i>Base 16</i>.
56
+ *
57
+ * @var integer
58
+ * @access public
59
+ */
60
+
61
+ public const E_BASE_16 = 0 ;
62
+
63
+ /**
64
+ * Encoding constant - for getting QR code image in <i>Base 32</i>.
65
+ *
66
+ * @var integer
67
+ * @access public
68
+ */
69
+
70
+ public const E_BASE_32 = 1 ;
54
71
55
72
/******************\
56
73
|* CORE VARIABLES *|
@@ -221,27 +238,45 @@ public function getFilename($account)
221
238
* @copyright 2018 All Rights Reserved
222
239
* @version 1.0.0
223
240
*
224
- * @return string
225
- * Encoded value of the generated QR code in <i>Base 32</i> format.
241
+ * @param $account
242
+ * Account that should be used for generating the QR code.
243
+ * @param integer $encoding
244
+ * ID of an encoding that should be used.
226
245
* @param integer $bufferSize
227
246
* Buffer size in bytes that will be used for loading.
228
247
* @return string
229
- * Encoded value of the QR code - Base 32 encoding .
248
+ * Encoded value of the QR code in a selected format .
230
249
*/
231
250
232
- public function getEncodedValue ($ account , $ bufferSize = 1024 )
251
+ public function getEncodedValue ($ account , $ encoding = 1 , $ bufferSize = 1024 )
233
252
{
234
253
// Core Variables
235
254
236
- $ encoder = new Base32 () ;
255
+ $ encoder = null ;
237
256
238
257
// File Variables
239
258
240
259
$ fileLocation = $ this ->getFileLocation ($ account );
241
260
$ fileHandler = null ;
242
261
$ fileData = null ;
243
262
244
- // Logic
263
+ // Step 1 -
264
+
265
+ switch ($ encoding )
266
+ {
267
+ case 0 :
268
+ $ encoder = new Base16 ();
269
+ break ;
270
+
271
+ case 1 :
272
+ $ encoder = new Base32 ();
273
+ break ;
274
+
275
+ default :
276
+ throw new \Exception ("Invalid encoding ID provided. " );
277
+ }
278
+
279
+ // Step 2 - Encode Generated Code
245
280
246
281
try
247
282
{
@@ -326,7 +361,7 @@ public function getUrl($account)
326
361
327
362
// Step 3 - Check Account Details
328
363
329
- if ($ account ->getServiceName () == "" && $ account ->getAccountName ())
364
+ if ($ account ->getServiceName () == "" && $ account ->getAccountName () == "" )
330
365
{
331
366
throw new \Exception ("Set account is without details. " );
332
367
}
0 commit comments