/** * Prepare the curl resource for sending a request. * * @param Request $request * * @return void */ public function prepareRequest(Request $request) { $this->ch = curl_init(); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->ch, CURLOPT_HEADER, true); if ($request->getUserAndPass()) { curl_setopt($this->ch, CURLOPT_USERPWD, $request->getUserAndPass()); } curl_setopt($this->ch, CURLOPT_URL, $request->getUrl()); $options = $request->getOptions(); if (!empty($options)) { curl_setopt_array($this->ch, $options); } $method = $request->getMethod(); if ($method === 'post') { curl_setopt($this->ch, CURLOPT_POST, 1); } elseif ($method !== 'get') { curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, strtoupper($method)); } curl_setopt($this->ch, CURLOPT_HTTPHEADER, $request->formatHeaders()); if ($this->methods[$method] === true) { curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request->encodeData()); } }