AbstractClient.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace OAuth\Common\Http\Client;
  3. /**
  4. * Abstract HTTP client
  5. */
  6. abstract class AbstractClient implements ClientInterface
  7. {
  8. /**
  9. * @var string The user agent string passed to services
  10. */
  11. protected $userAgent;
  12. /**
  13. * @var int The maximum number of redirects
  14. */
  15. protected $maxRedirects = 5;
  16. /**
  17. * @var int The maximum timeout
  18. */
  19. protected $timeout = 15;
  20. /**
  21. * Creates instance
  22. *
  23. * @param string $userAgent The UA string the client will use
  24. */
  25. public function __construct($userAgent = 'PHPoAuthLib')
  26. {
  27. $this->userAgent = $userAgent;
  28. }
  29. /**
  30. * @param int $redirects Maximum redirects for client
  31. *
  32. * @return ClientInterface
  33. */
  34. public function setMaxRedirects($redirects)
  35. {
  36. $this->maxRedirects = $redirects;
  37. return $this;
  38. }
  39. /**
  40. * @param int $timeout Request timeout time for client in seconds
  41. *
  42. * @return ClientInterface
  43. */
  44. public function setTimeout($timeout)
  45. {
  46. $this->timeout = $timeout;
  47. return $this;
  48. }
  49. /**
  50. * @param array $headers
  51. */
  52. public function normalizeHeaders(&$headers)
  53. {
  54. // Normalize headers
  55. array_walk(
  56. $headers,
  57. function (&$val, &$key) {
  58. $key = ucfirst(strtolower($key));
  59. $val = ucfirst(strtolower($key)) . ': ' . $val;
  60. }
  61. );
  62. }
  63. }