RequestToken::get()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
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
     *
28
     * @return string
29
     */
30
    public function get(string $handle): string
31
    {
32
        if (!in_array($handle, $this->handles)) {
33
            throw new JwtException('不支持此方式获取.', 500);
34
        }
35
36
        $this->token = (new Header($this->app))->handle();
37
38
        if (!$this->token) {
39
            throw new JwtException('获取Token失败.', 500);
40
        }
41
42
        return $this->token;
43
    }
44
}
45