/
CurlResponse.php
executable file
·71 lines (57 loc) · 1.44 KB
/
CurlResponse.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
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* A wrapper to handle a curl response.
*
* @package PHPTwitter
**/
class CurlResponse {
/**
* Store the http status code.
* @var int
**/
protected $statusCode = 0;
/**
* Stores the headers of a curl response
* @var array
**/
protected $headers = array();
/**
* Stores the unparsed body of a curl response
* @var string
**/
protected $body = "";
/**
* Executes the curl request and deals with the response.
* @param $ch - valid curl handle.
* @param $close boolean - whether to close the curl handle after setup. default: true
**/
public function __construct(&$ch, $close = true) {
$this->body = (string) curl_exec($ch);
$this->statusCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->headers = (array) curl_getinfo($ch);
if($close == true)
curl_close($ch);
}
/**
* Returns the status code of the response
* @return int
**/
public function statusCode() {
return (int) $this->statusCode;
}
/**
* Returns the headers from the curl response
* @return array
**/
public function headers() {
return (array) $this->headers;
}
/**
* Returns the unparsed body of the response
* @return (string)
**/
public function body() {
return (string) $this->body;
}
}
?>