Request.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: perfectmak
  5. * Date: 2/12/16
  6. * Time: 5:53 PM
  7. */
  8. namespace Paystack;
  9. use Paystack\Interfaces\Http\IClient;
  10. use Paystack\Interfaces\IRequest;
  11. class Request implements IRequest
  12. {
  13. private $_type = false;
  14. private $_headers = [];
  15. private $_body = '';
  16. private $_url = '';
  17. /**
  18. * @var IClient
  19. */
  20. private static $_httpClient = null;
  21. public function setHeader($key, $value)
  22. {
  23. $this->_headers[$key] = $value;
  24. return $this;
  25. }
  26. public function getHeader($key)
  27. {
  28. return $this->_headers[$key];
  29. }
  30. public function getHeaders()
  31. {
  32. return $this->_headers;
  33. }
  34. public function setBody($body)
  35. {
  36. $this->_body = $body;
  37. return $this;
  38. }
  39. public function getBody()
  40. {
  41. return $this->_body;
  42. }
  43. public function setUrl($url)
  44. {
  45. $this->_url = $url;
  46. return $this;
  47. }
  48. public function getUrl()
  49. {
  50. return $this->_url;
  51. }
  52. public function setType($type)
  53. {
  54. $this->_type = $type;
  55. return $this;
  56. }
  57. public function getType()
  58. {
  59. return $this->_type;
  60. }
  61. public static function setClient(IClient $client)
  62. {
  63. self::$_httpClient = $client;
  64. }
  65. public static function getClient()
  66. {
  67. return self::$_httpClient;
  68. }
  69. public function send()
  70. {
  71. if(!is_null(self::$_httpClient))
  72. return self::$_httpClient->sendRequest($this);
  73. throw new \Exception('No HttpClient specified for requests');
  74. }
  75. }