1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2016 Facebook, Inc. |
4
|
|
|
* |
5
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to |
6
|
|
|
* use, copy, modify, and distribute this software in source code or binary |
7
|
|
|
* form for use in connection with the web services and APIs provided by |
8
|
|
|
* Facebook. |
9
|
|
|
* |
10
|
|
|
* As with any software that integrates with the Facebook platform, your use |
11
|
|
|
* of this software is subject to the Facebook Developer Principles and |
12
|
|
|
* Policies [http://developers.facebook.com/policy/]. This copyright notice |
13
|
|
|
* shall be included in all copies or substantial portions of the software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
20
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21
|
|
|
* DEALINGS IN THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
namespace Facebook\HttpClients; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class FacebookCurl |
28
|
|
|
* |
29
|
|
|
* Abstraction for the procedural curl elements so that curl can be mocked and the implementation can be tested. |
30
|
|
|
* |
31
|
|
|
* @package Facebook |
32
|
|
|
*/ |
33
|
|
|
class FacebookCurl |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var resource Curl resource instance |
38
|
|
|
*/ |
39
|
|
|
protected $curl; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Make a new curl reference instance |
43
|
|
|
*/ |
44
|
|
|
public function init() |
45
|
|
|
{ |
46
|
|
|
$this->curl = curl_init(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Set a curl option |
51
|
|
|
* |
52
|
|
|
* @param $key |
53
|
|
|
* @param $value |
54
|
|
|
*/ |
55
|
|
|
public function setopt($key, $value) |
56
|
|
|
{ |
57
|
|
|
curl_setopt($this->curl, $key, $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Set an array of options to a curl resource |
62
|
|
|
* |
63
|
|
|
* @param array $options |
64
|
|
|
*/ |
65
|
|
|
public function setoptArray(array $options) |
66
|
|
|
{ |
67
|
|
|
curl_setopt_array($this->curl, $options); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Send a curl request |
72
|
|
|
* |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
|
|
public function exec() |
76
|
|
|
{ |
77
|
|
|
return curl_exec($this->curl); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Return the curl error number |
82
|
|
|
* |
83
|
|
|
* @return int |
84
|
|
|
*/ |
85
|
|
|
public function errno() |
86
|
|
|
{ |
87
|
|
|
return curl_errno($this->curl); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Return the curl error message |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function error() |
96
|
|
|
{ |
97
|
|
|
return curl_error($this->curl); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get info from a curl reference |
102
|
|
|
* |
103
|
|
|
* @param $type |
104
|
|
|
* |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function getinfo($type) |
108
|
|
|
{ |
109
|
|
|
return curl_getinfo($this->curl, $type); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get the currently installed curl version |
114
|
|
|
* |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
|
|
public function version() |
118
|
|
|
{ |
119
|
|
|
return curl_version(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Close the resource connection to curl |
124
|
|
|
*/ |
125
|
|
|
public function close() |
126
|
|
|
{ |
127
|
|
|
curl_close($this->curl); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|