1 | <?php |
||
13 | class CurlBuilder { |
||
14 | |||
15 | /** |
||
16 | * Contains the curl instance |
||
17 | * |
||
18 | * @var resource |
||
19 | */ |
||
20 | private $curl; |
||
21 | |||
22 | /** |
||
23 | * Array containing headers from last performed request |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | private $headers; |
||
28 | |||
29 | /** |
||
30 | * Constructor |
||
31 | */ |
||
32 | 37 | public function __construct() |
|
36 | |||
37 | /** |
||
38 | * Return a new instance of the CurlBuilder |
||
39 | * |
||
40 | * @access public |
||
41 | * @return CurlBuilder |
||
42 | */ |
||
43 | public function create() |
||
47 | |||
48 | /** |
||
49 | * Sets an option in the curl instance |
||
50 | * |
||
51 | * @access public |
||
52 | * @param string $option |
||
53 | * @param false|string $value |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function setOption($option, $value) |
||
57 | { |
||
58 | curl_setopt($this->curl, $option, $value); |
||
59 | |||
60 | return $this; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Sets multiple options at the same time |
||
65 | * |
||
66 | * @access public |
||
67 | * @param array $options |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function setOptions(array $options = []) |
||
71 | { |
||
72 | curl_setopt_array($this->curl, $options); |
||
73 | |||
74 | return $this; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Execute the curl request |
||
79 | * |
||
80 | * @access public |
||
81 | * @return false|string |
||
82 | */ |
||
83 | public function execute() |
||
87 | |||
88 | /** |
||
89 | * Check if the curl request ended up with errors |
||
90 | * |
||
91 | * @access public |
||
92 | * @return integer |
||
93 | */ |
||
94 | public function hasErrors() |
||
98 | |||
99 | /** |
||
100 | * Get curl errors |
||
101 | * |
||
102 | * @access public |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getErrors() |
||
109 | |||
110 | /** |
||
111 | * Get last curl error number |
||
112 | * |
||
113 | * @access public |
||
114 | * @return int |
||
115 | */ |
||
116 | public function getErrorNumber() |
||
120 | |||
121 | /** |
||
122 | * Get curl info key |
||
123 | * |
||
124 | * @access public |
||
125 | * @param string $key |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getInfo($key) |
||
132 | |||
133 | /** |
||
134 | * Get headers |
||
135 | * |
||
136 | * @access public |
||
137 | * @return string |
||
138 | */ |
||
139 | public function getHeaders() |
||
143 | |||
144 | /** |
||
145 | * Close the curl resource |
||
146 | * |
||
147 | * @access public |
||
148 | * @return void |
||
149 | */ |
||
150 | public function close() |
||
154 | |||
155 | /** |
||
156 | * Parse string headers into array |
||
157 | * |
||
158 | * @access private |
||
159 | * @param string $headers |
||
160 | * @return array |
||
161 | */ |
||
162 | private function parseHeaders($headers) { |
||
174 | |||
175 | /** |
||
176 | * Function which acts as a replacement for curl's default |
||
177 | * FOLLOW_LOCATION option, since that gives errors when |
||
178 | * combining it with open basedir. |
||
179 | * |
||
180 | * @see http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/ |
||
181 | * @access private |
||
182 | * @return false|string |
||
183 | */ |
||
184 | private function execFollow() { |
||
253 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: