Example #1
0
 public static function initBignum($how = NULL)
 {
     /* Check to see if PHP is running in a 32-bit environment and if so,
        use GMP or BC Math if available. */
     if ($how === NULL) {
         if (self::$bignum != self::bigChoose) {
             // determination has already been made
             return self::$bignum;
         } else {
             if (PHP_INT_SIZE >= 8) {
                 self::$bignum = self::bigNative;
             } else {
                 if (function_exists("gmp_add")) {
                     self::$bignum = self::bigGMP;
                 } else {
                     if (function_exists("bcadd")) {
                         self::$bignum = self::bigBC;
                     } else {
                         if (class_exists("\\phpseclib\\Math\\BigInteger", 0)) {
                             // phpseclib v2.x
                             self::$bignum = self::bigSecLib;
                             self::$secLib = "\\phpseclib\\Math\\BigInteger";
                         } else {
                             if (class_exists("Math_BigInteger", 0)) {
                                 // phpseclib v1.x
                                 self::$bignum = self::bigSecLib;
                                 self::$secLib = "Math_BigInteger";
                             } else {
                                 self::$bignum = self::bigNot;
                             }
                         }
                     }
                 }
             }
         }
     } else {
         switch ($how) {
             case self::bigChoose:
                 self::$bignum = $how;
                 return self::initBignum();
             case self::bigNot:
                 break;
             case self::bigNative:
                 if (PHP_INT_SIZE < 8) {
                     throw new UUIDException("Bignum method is not available.", 801);
                 }
                 break;
             case self::bigGMP:
                 if (!function_exists("gmp_add")) {
                     throw new UUIDException("Bignum method is not available.", 801);
                 }
                 break;
             case self::bigBC:
                 if (!function_exists("bcadd")) {
                     throw new UUIDException("Bignum method is not available.", 801);
                 }
                 break;
             case self::bigSecLib:
                 if (class_exists("\\phpseclib\\Math\\BigInteger", 0)) {
                     //v2.x
                     self::$secLib = "\\phpseclib\\Math\\BigInteger";
                 } else {
                     if (class_exists("Math_BigInteger", 0)) {
                         //v1.x
                         self::$secLib = "Math_BigInteger";
                     } else {
                         throw new UUIDException("Bignum method is not available.", 801);
                     }
                 }
                 break;
             default:
                 throw new UUIDException("Bignum method not implemented.", 901);
         }
         self::$bignum = $how;
     }
     return self::$bignum;
 }