1 | <?php |
||
15 | class CurlBuilder { |
||
16 | |||
17 | /** |
||
18 | * Contains the curl instance |
||
19 | * |
||
20 | * @var resource |
||
21 | */ |
||
22 | private $curl; |
||
23 | |||
24 | /** |
||
25 | * Array containing headers from last performed request |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $headers; |
||
30 | |||
31 | /** |
||
32 | * Constructor |
||
33 | */ |
||
34 | 43 | public function __construct() |
|
38 | |||
39 | /** |
||
40 | * Return a new instance of the CurlBuilder |
||
41 | * |
||
42 | * @access public |
||
43 | * @return CurlBuilder |
||
44 | */ |
||
45 | public function create() |
||
49 | |||
50 | /** |
||
51 | * Sets an option in the curl instance |
||
52 | * |
||
53 | * @access public |
||
54 | * @param string $option |
||
55 | * @param false|string $value |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function setOption($option, $value) |
||
64 | |||
65 | /** |
||
66 | * Sets multiple options at the same time |
||
67 | * |
||
68 | * @access public |
||
69 | * @param array $options |
||
70 | * @return $this |
||
71 | */ |
||
72 | public function setOptions(array $options = []) |
||
78 | |||
79 | /** |
||
80 | * Execute the curl request |
||
81 | * |
||
82 | * @access public |
||
83 | * @return false|string |
||
84 | */ |
||
85 | public function execute() |
||
89 | |||
90 | /** |
||
91 | * Check if the curl request ended up with errors |
||
92 | * |
||
93 | * @access public |
||
94 | * @return integer |
||
95 | */ |
||
96 | public function hasErrors() |
||
100 | |||
101 | /** |
||
102 | * Get curl errors |
||
103 | * |
||
104 | * @access public |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getErrors() |
||
111 | |||
112 | /** |
||
113 | * Get last curl error number |
||
114 | * |
||
115 | * @access public |
||
116 | * @return int |
||
117 | */ |
||
118 | public function getErrorNumber() |
||
122 | |||
123 | /** |
||
124 | * Get curl info key |
||
125 | * |
||
126 | * @access public |
||
127 | * @param string $key |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getInfo($key) |
||
134 | |||
135 | /** |
||
136 | * Get headers |
||
137 | * |
||
138 | * @access public |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getHeaders() |
||
145 | |||
146 | /** |
||
147 | * Close the curl resource |
||
148 | * |
||
149 | * @access public |
||
150 | * @return void |
||
151 | */ |
||
152 | public function close() |
||
156 | |||
157 | /** |
||
158 | * Parse string headers into array |
||
159 | * |
||
160 | * @access private |
||
161 | * @param string $headers |
||
162 | * @return array |
||
163 | */ |
||
164 | private function parseHeaders($headers) { |
||
176 | |||
177 | /** |
||
178 | * Function which acts as a replacement for curl's default |
||
179 | * FOLLOW_LOCATION option, since that gives errors when |
||
180 | * combining it with open basedir. |
||
181 | * |
||
182 | * @see http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/ |
||
183 | * @access private |
||
184 | * @return false|string |
||
185 | */ |
||
186 | private function execFollow() { |
||
257 | } |
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: