Total Complexity | 10 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | trait SchemeAttribute |
||
9 | { |
||
10 | protected $host; |
||
11 | protected $port; |
||
12 | protected $scheme; |
||
13 | |||
14 | public function getScheme() |
||
15 | { |
||
16 | $server = $this->getServer(); |
||
17 | if (!isset($this->scheme)) { |
||
18 | if (array_key_exists('HTTPS', $server) && strcasecmp($server['HTTPS'], 'off') != 0) { |
||
19 | $scheme = 'https'; |
||
20 | } elseif (array_key_exists('REQUEST_SCHEME', $server)) { |
||
21 | $scheme = $server['REQUEST_SCHEME']; |
||
22 | } else { |
||
23 | $scheme = 'http'; |
||
24 | } |
||
25 | } |
||
26 | return $this->scheme = $scheme; |
||
|
|||
27 | } |
||
28 | |||
29 | public function getHost() |
||
35 | } |
||
36 | |||
37 | public function getPort() |
||
38 | { |
||
39 | if (isset($this->port)) { |
||
40 | return $this->port; |
||
41 | } |
||
42 | return $this->port = $this->getServer()['SERVER_PORT'] ?? 80; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * 获取服务器基础URI |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getServerURI() |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get 服务器属性 |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | abstract public function getServer(); |
||
61 | } |
||
62 |