/**
  * @param string $level
  * @param RequestInterface $request
  * @param array $context
  */
 public function logRequest($level, RequestInterface $request, array $context = array())
 {
     $msg = "[FacebookAPI] [Response] \n";
     $msg = trim($request->getMethod() . ' ' . $request->getUrl());
     foreach ($request->getHeaders() as $name => $value) {
         $msg .= "\r\n{$name}: " . $value;
     }
     $message = "{$msg}\r\n\r\n" . implode("\n", $request->getBodyParams()->export());
     $this->logger->log($level, $message, $context);
 }
 /**
  * @param RequestInterface $request
  * @return ResponseInterface
  * @throws Exception
  */
 public function sendRequest(RequestInterface $request)
 {
     $response = $this->getClient()->createResponse();
     $this->getCurl()->reset();
     $curlopts = array(CURLOPT_URL => $request->getUrl());
     $method = $request->getMethod();
     if ($method !== RequestInterface::METHOD_GET && $method !== RequestInterface::METHOD_POST) {
         $curlopts[CURLOPT_CUSTOMREQUEST] = $method;
     }
     $curlopts = $this->getOpts()->getArrayCopy() + $curlopts;
     if ($request->getHeaders()->count()) {
         $headers = array();
         foreach ($request->getHeaders() as $header => $value) {
             $headers[] = "{$header}: {$value}";
         }
         $curlopts[CURLOPT_HTTPHEADER] = $headers;
     }
     $postfields = array();
     if ($method === RequestInterface::METHOD_POST && $request->getFileParams()->count()) {
         $postfields = array_merge($postfields, array_map(array($this->getCurl(), 'preparePostFileField'), $request->getFileParams()->getArrayCopy()));
     }
     if ($method !== RequestInterface::METHOD_GET && $request->getBodyParams()->count()) {
         $postfields = array_merge($postfields, $request->getBodyParams()->export());
     }
     if (!empty($postfields)) {
         $curlopts[CURLOPT_POSTFIELDS] = $postfields;
     }
     $this->getCurl()->setoptArray($curlopts);
     $raw_response = $this->getCurl()->exec();
     $status_code = $this->getCurl()->getInfo(CURLINFO_HTTP_CODE);
     $curl_errno = $this->getCurl()->errno();
     $curl_error = $curl_errno ? $this->getCurl()->error() : null;
     $response_parts = $this->extractResponseHeadersAndBody($raw_response);
     $response->setStatusCode($status_code);
     $this->parseHeaders($response->getHeaders(), $response_parts[0]);
     $response->setBody($response_parts[1]);
     if ($curl_errno) {
         throw new Exception($curl_error, $curl_errno);
     }
     return $response;
 }