Beispiel #1
0
 /**
  * Creates CurlWrapper from given Request object.
  *
  * @param Request $request
  * @param string $requestId
  * @throws DirectoryNotWritableException
  * @return CurlWrapper
  */
 protected function initRequest(Request $request, &$requestId)
 {
     // combine setup
     $request->options += $this->options;
     $request->headers += $this->headers;
     // cookies
     if ($request->cookies) {
         $request->headers['Cookie'] = $request->getCookies();
     }
     // wrap
     $curl = new CurlWrapper($request->getUrl(), $request->method);
     $curl->setOptions($request->options);
     $curl->setHeaders($request->headers);
     $curl->setPost($request->post, $request->files);
     // fallback when safe_mode
     if (!$this->canFollowRedirect()) {
         $curl->setOption('followLocation', NULL);
     }
     // method & prepare download
     if ($request->isMethod(Request::DOWNLOAD)) {
         if (!is_dir($this->downloadDir)) {
             throw new DirectoryNotWritableException("Please provide a writable directory for download.");
         }
         FileResponse::prepareDownload($curl, $this->downloadDir);
     } else {
         $curl->setOption('header', TRUE);
     }
     // logging
     if ($this->logger) {
         $requestId = $this->logger->request($request);
     }
     return $curl;
 }
Beispiel #2
0
 /**
  * @param array $data
  * @throws CommunicationFailedException
  * @return array
  */
 private function process($data)
 {
     $this->onRequest($data);
     $data = array('USER' => $this->username, 'PWD' => $this->password, 'SIGNATURE' => $this->signature, 'VERSION' => self::API_VERSION) + $data;
     $request = new Curl\Request($this->host, $data);
     $request->setSender($this->curlSender);
     $request->options['verbose'] = TRUE;
     if (strpos($request->getUrl()->getHost(), '.sandbox.') !== FALSE) {
         $request->setCertificationVerify(FALSE);
         $request->options['ssl_verifyHost'] = FALSE;
     }
     try {
         $response = $request->post(http_build_query($data));
         $resultData = self::parseNvp($response->getResponse());
         $this->onSuccess($resultData, $response->getInfo());
         return $resultData;
     } catch (Curl\FailedRequestException $e) {
         $this->onError($e, $e->getInfo());
         throw new CommunicationFailedException($e->getMessage(), 0, $e);
     } catch (Curl\CurlException $e) {
         $this->onError($e, $e->getResponse() ? $e->getResponse()->info : array());
         throw new CommunicationFailedException($e->getMessage(), 0, $e);
     }
 }