PageRenderTime 31ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/plugin/PBAPI/PBAPI/Request/curl.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/
PHP | 73 lines | 31 code | 10 blank | 32 comment | 4 complexity | 7ac93707136eead1eeb7d94d070fabc8 MD5 | raw file
  1. <?php
  2. use common\libraries\Path;
  3. /**
  4. * Photobucket API
  5. * Fluent interface for PHP5
  6. * CURL request interface
  7. *
  8. * @author Photobucket
  9. * @package PBAPI
  10. * @subpackage Request
  11. *
  12. * @copyright Copyright Copyright (c) 2008, Photobucket, Inc.
  13. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  14. */
  15. /**
  16. * Load Request parent
  17. */
  18. require_once dirname(__FILE__) . '/../Request.php';
  19. /**
  20. * CURL request strategy
  21. * Requires CURL to be available and loaded
  22. *
  23. * @package PBAPI
  24. * @subpackage Request
  25. */
  26. class PBAPI_Request_curl extends PBAPI_Request
  27. {
  28. /**
  29. * Do actual request
  30. *
  31. * @param string $method
  32. * @param string $uri
  33. * @param array $params
  34. * @return string
  35. */
  36. protected function request($method, $uri, $params = array())
  37. {
  38. $url = $this->preRequest($method, $uri, $params);
  39. $curl_opts = $this->request_params;
  40. //overridable
  41. if (empty($curl_opts[CURLOPT_USERAGENT]))
  42. $curl_opts[CURLOPT_USERAGENT] = __CLASS__;
  43. //static
  44. $curl_opts[CURLOPT_HEADER] = 0;
  45. $curl_opts[CURLOPT_FOLLOWLOCATION] = 1;
  46. $curl_opts[CURLOPT_RETURNTRANSFER] = 1;
  47. $curl_opts[CURLOPT_CUSTOMREQUEST] = $method;
  48. if ($method == 'POST')
  49. {
  50. $curl_opts[CURLOPT_POST] = 1;
  51. $curl_opts[CURLOPT_POSTFIELDS] = $params;
  52. }
  53. $ch = curl_init($url);
  54. curl_setopt_array($ch, $curl_opts);
  55. $data = curl_exec($ch);
  56. if ($cerror = curl_errno($ch))
  57. {
  58. throw new PBAPI_Exception('CURL: ' . curl_error($ch), $cerror);
  59. }
  60. curl_close($ch);
  61. return $data;
  62. }
  63. }