Emarref\Jwt\Encryption\Factory::create PHP Метод

create() публичный статический Метод

public static create ( Emarref\Jwt\Algorithm\AlgorithmInterface $algorithm ) : Asymmetric | Symmetric
$algorithm Emarref\Jwt\Algorithm\AlgorithmInterface
Результат Asymmetric | Symmetric
    public static function create(Algorithm\AlgorithmInterface $algorithm)
    {
        if ($algorithm instanceof Algorithm\AsymmetricInterface) {
            $encryption = new Asymmetric($algorithm);
        } elseif ($algorithm instanceof Algorithm\SymmetricInterface) {
            $encryption = new Symmetric($algorithm);
        } else {
            throw new \InvalidArgumentException(sprintf('Algorithm of class "%s" is neither symmetric or asymmetric.', get_class($algorithm)));
        }
        return $encryption;
    }

Usage Example

Пример #1
0
 protected static function authorization()
 {
     $token = new Emarref\Jwt\Token();
     $parameter = new Emarref\Jwt\HeaderParameter\Custom('typ', 'JWT');
     $token->addHeader($parameter, true);
     $token->addClaim(new Emarref\Jwt\Claim\Expiration(new \DateTime(self::$duration)));
     $jwt = new Emarref\Jwt\Jwt();
     $algorithm = new Emarref\Jwt\Algorithm\Hs256(self::$appSecret);
     $encryption = Emarref\Jwt\Encryption\Factory::create($algorithm);
     $serializedToken = $jwt->serialize($token, $encryption);
     return $serializedToken;
 }
All Usage Examples Of Emarref\Jwt\Encryption\Factory::create
Factory