-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCurlHttp.php
60 lines (50 loc) · 1.3 KB
/
CurlHttp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace lspbupt\curl;
use Closure;
class CurlHttp extends \lspbupt\curl\BaseCurlHttp
{
// closure
public $beforeRequest;
public $afterRequest;
protected $enableAudit = false;
//请求之前的操作
protected function beforeCurl($params)
{
if ($this->beforeRequest instanceof Closure) {
$params = call_user_func($this->beforeRequest, $params, $this);
empty($params) && $params = [];
$this->setParams($params);
}
return parent::beforeCurl($params);
}
//请求之后的操作
protected function afterCurl($data)
{
if ($this->afterRequest instanceof Closure) {
$data = call_user_func($this->afterRequest, $data, $this);
}
return parent::afterCurl($data);
}
public function setEnableAudit()
{
$this->enableAudit = true;
return $this;
}
public function beforeCurlExec(&$ch)
{
if ($this->enableAudit) {
$this->trigger('auditBeforeCurlExec');
}
}
public function afterCurlExec(&$ch)
{
if ($this->enableAudit) {
$this->trigger('auditAfterCurlExec');
}
}
public function refreshCurl()
{
$this->enableAudit = false;
parent::refreshCurl();
}
}