1 | <?php namespace CodeZero\Curl; |
||
3 | class Curl |
||
4 | { |
||
5 | /** |
||
6 | * cURL Resource Handle |
||
7 | * |
||
8 | * @var resource |
||
9 | */ |
||
10 | private $curl; |
||
11 | |||
12 | /** |
||
13 | * cURL Response |
||
14 | * |
||
15 | * @var bool|string |
||
16 | */ |
||
17 | private $response; |
||
18 | |||
19 | /** |
||
20 | * Constructor |
||
21 | * |
||
22 | * @throws CurlException |
||
23 | */ |
||
24 | public function __construct() |
||
31 | |||
32 | /** |
||
33 | * Initialize a new cURL resource |
||
34 | * |
||
35 | * @return bool |
||
36 | * @throws CurlException |
||
37 | */ |
||
38 | public function initialize() |
||
52 | |||
53 | /** |
||
54 | * Check if a cURL resource has been initialized |
||
55 | * |
||
56 | * @return bool |
||
57 | */ |
||
58 | public function isInitialized() |
||
62 | |||
63 | /** |
||
64 | * Set cURL option |
||
65 | * |
||
66 | * @param int $option |
||
67 | * @param mixed $value |
||
68 | * |
||
69 | * @return bool |
||
70 | * @throws CurlException |
||
71 | */ |
||
72 | public function setOption($option, $value) |
||
78 | |||
79 | /** |
||
80 | * Set cURL options |
||
81 | * |
||
82 | * @param array $options |
||
83 | * |
||
84 | * @return bool |
||
85 | * @throws CurlException |
||
86 | */ |
||
87 | public function setOptions(array $options) |
||
93 | |||
94 | /** |
||
95 | * Send the cURL request (will initialize if needed and set options if provided) |
||
96 | * |
||
97 | * !!! Options that have already been set are not automatically reset !!! |
||
98 | * |
||
99 | * @param array $options |
||
100 | * |
||
101 | * @return bool|string |
||
102 | * @throws CurlException |
||
103 | */ |
||
104 | public function sendRequest(array $options = []) |
||
120 | |||
121 | /** |
||
122 | * Get the response of the last cURL request |
||
123 | * |
||
124 | * @return bool|string |
||
125 | */ |
||
126 | public function getResponse() |
||
130 | |||
131 | /** |
||
132 | * Get additional information about the last cURL request |
||
133 | * |
||
134 | * @param string $key |
||
135 | * |
||
136 | * @return string|array |
||
137 | */ |
||
138 | public function getRequestInfo($key = null) |
||
147 | |||
148 | /** |
||
149 | * Get the error from the last cURL request |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getError() |
||
163 | |||
164 | /** |
||
165 | * Get the error code from the last cURL request |
||
166 | * |
||
167 | * @return int |
||
168 | */ |
||
169 | public function getErrorCode() |
||
173 | |||
174 | /** |
||
175 | * Get the error description from the last cURL request |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getErrorDescription() |
||
183 | |||
184 | /** |
||
185 | * URL encodes the given string |
||
186 | * |
||
187 | * @param string $string |
||
188 | * |
||
189 | * @return string|bool |
||
190 | * @throws CurlException |
||
191 | */ |
||
192 | public function urlEncode($string) |
||
196 | |||
197 | /** |
||
198 | * Decodes the given URL encoded string |
||
199 | * |
||
200 | * @param string $string |
||
201 | * |
||
202 | * @return string|bool |
||
203 | * @throws CurlException |
||
204 | */ |
||
205 | public function urlDecode($string) |
||
209 | |||
210 | /** |
||
211 | * Reset all cURL options |
||
212 | * |
||
213 | * @return void |
||
214 | * @throws CurlException |
||
215 | */ |
||
216 | public function reset() |
||
230 | |||
231 | /** |
||
232 | * Close the cURL resource |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | public function close() |
||
246 | |||
247 | /** |
||
248 | * Get the cURL version |
||
249 | * |
||
250 | * @return string |
||
251 | */ |
||
252 | public function getVersion() |
||
256 | |||
257 | /** |
||
258 | * Destructor |
||
259 | */ |
||
260 | public function __destruct() |
||
264 | |||
265 | /** |
||
266 | * Initialize cURL if it has not been initialized yet |
||
267 | * |
||
268 | * @throws CurlException |
||
269 | */ |
||
270 | private function autoInitialize() |
||
277 | |||
278 | /** |
||
279 | * Encode or decode a URL |
||
280 | * |
||
281 | * @param string $string |
||
282 | * @param bool $decode |
||
283 | * |
||
284 | * @return bool|string |
||
285 | */ |
||
286 | private function parseUrl($string, $decode) |
||
300 | } |
||
301 |