GatewayTrait::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
namespace tinymeng\OAuth2\Connector;
3
4
use tinymeng\tools\HttpRequest;
5
6
trait GatewayTrait
7
{
8
9
    /**
10
     * headers
11
     * @var array
12
     */
13
    protected $headers = [];
14
15
    /**
16
     * @return array
17
     */
18
    public function getHeaders(): array
19
    {
20
        return $this->headers;
21
    }
22
    /**
23
     * @var 缓存处理
0 ignored issues
show
Documentation Bug introduced by
The doc comment 缓存处理 at position 0 could not be parsed: Unknown type name '缓存处理' at position 0 in 缓存处理.
Loading history...
24
     */
25
    protected $cache;
26
27
    /**
28
     * Description:  执行GET请求操作
29
     * @author: JiaMeng <[email protected]>
30
     * Updater:
31
     * @param $url
32
     * @param array $params
33
     * @param array $headers
34
     * @return string
35
     */
36
    protected function get($url, $params = [], $headers = [])
37
    {
38
        return HttpRequest::httpGet($url, $params,$headers);
39
    }
40
41
    /**
42
     * Description:  执行POST请求操作
43
     * @author: JiaMeng <[email protected]>
44
     * Updater:
45
     * @param $url
46
     * @param array $params
47
     * @param array $headers
48
     * @return mixed
49
     */
50
    protected function post($url, $params = [], $headers = [])
51
    {
52
        return HttpRequest::httpPost($url, $params,$headers);
53
    }
54
55
56
    public function setCache($cache)
57
    {
58
        $this->cache = $cache;
59
        return $this;
60
    }
61
62
    protected function getTokenFromCache($key)
63
    {
64
        return $this->cache ? $this->cache->get($key) : null;
65
    }
66
67
    protected function setTokenToCache($key, $token, $expires = 7200)
68
    {
69
        if ($this->cache) {
70
            $this->cache->set($key, $token, $expires);
71
        }
72
    }
73
74
}