RobThree\Auth\TwoFactorAuth::__construct PHP Method

__construct() public method

public __construct ( $issuer = null, $digits = 6, $period = 30, $algorithm = 'sha1', $qrcodeprovider = null, $rngprovider = null )
    function __construct($issuer = null, $digits = 6, $period = 30, $algorithm = 'sha1', $qrcodeprovider = null, $rngprovider = null)
    {
        $this->issuer = $issuer;
        if (!is_int($digits) || $digits <= 0) {
            throw new TwoFactorAuthException('Digits must be int > 0');
        }
        $this->digits = $digits;
        if (!is_int($period) || $period <= 0) {
            throw new TwoFactorAuthException('Period must be int > 0');
        }
        $this->period = $period;
        $algorithm = strtolower(trim($algorithm));
        if (!in_array($algorithm, self::$_supportedalgos)) {
            throw new TwoFactorAuthException('Unsupported algorithm: ' . $algorithm);
        }
        $this->algorithm = $algorithm;
        // Set default QR Code provider if none was specified
        if ($qrcodeprovider == null) {
            $qrcodeprovider = new Providers\Qr\GoogleQRCodeProvider();
        }
        if (!$qrcodeprovider instanceof Providers\Qr\IQRCodeProvider) {
            throw new TwoFactorAuthException('QRCodeProvider must implement IQRCodeProvider');
        }
        $this->qrcodeprovider = $qrcodeprovider;
        // Try to find best available RNG provider if none was specified
        if ($rngprovider == null) {
            if (function_exists('random_bytes')) {
                $rngprovider = new Providers\Rng\CSRNGProvider();
            } elseif (function_exists('mcrypt_create_iv')) {
                $rngprovider = new Providers\Rng\MCryptRNGProvider();
            } elseif (function_exists('openssl_random_pseudo_bytes')) {
                $rngprovider = new Providers\Rng\OpenSSLRNGProvider();
            } elseif (function_exists('hash')) {
                $rngprovider = new Providers\Rng\HashRNGProvider();
            } else {
                throw new TwoFactorAuthException('Unable to find a suited RNGProvider');
            }
        }
        if (!$rngprovider instanceof Providers\Rng\IRNGProvider) {
            throw new TwoFactorAuthException('RNGProvider must implement IRNGProvider');
        }
        $this->rngprovider = $rngprovider;
        self::$_base32 = str_split(self::$_base32dict);
        self::$_base32lookup = array_flip(self::$_base32);
    }