Completed
Push — master ( 7eb1a4...254269 )
by LEUNG
03:41
created

RequestToken   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getToken() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace xiaodi\JWTAuth\Handle;
6
7
use think\App;
8
use xiaodi\JWTAuth\Exception\JWTException;
9
10
class RequestToken
11
{
12
    protected $handles = ['Header', 'Url', 'Cookie'];
13
14
    protected $token;
15
16
    protected $app;
17
18
    public function __construct(App $app)
19
    {
20
        $this->app = $app;
21
    }
22
23
    /**
24
     * 获取请求Token
25
     *
26
     * @param string $handle
27
     * @return String
28
     */
29
    public function getToken(string $handle): String
30
    {
31
        if (!in_array($handle, $this->handles)) {
32
            throw new JwtException('不支持只方式获取.', 500);
33
        }
34
35
        $this->token = (new Header($this->app))->handle();
36
37
        if (!$this->token) {
38
            throw new JwtException('获取Token失败.', 500);
39
        }
40
41
        return $this->token;
42
    }
43
}
44