1 | <?php |
||
4 | class HttpRequest |
||
5 | { |
||
6 | const REQUEST_METHOD_GET = 'GET'; |
||
7 | const REQUEST_METHOD_POST = 'POST'; |
||
8 | const REQUEST_METHOD_PUT = 'PUT'; |
||
9 | const REQUEST_EXPECTED_RESPONSE_TYPE_JSON = 'JSON'; |
||
10 | |||
11 | /** |
||
12 | * @var int |
||
13 | */ |
||
14 | protected $httpResponseCode; |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $responseHeaders; |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $responseBody; |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $requestMethod; |
||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $requestHeaders; |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $expectedType; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $postBody; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $url; |
||
45 | |||
46 | public function __construct($url = '', $method = 'GET', $headers = array(), $post_body = array(), $expected_type = self::REQUEST_EXPECTED_RESPONSE_TYPE_JSON) |
||
54 | |||
55 | /** |
||
56 | * @param string $expectedType XML/JSON |
||
57 | */ |
||
58 | public function setExpectedType($expectedType) |
||
62 | |||
63 | /** |
||
64 | * @param integer $httpResponseCode HTTP Response code |
||
65 | */ |
||
66 | public function setHttpResponseCode($httpResponseCode) |
||
70 | |||
71 | /** |
||
72 | * @param array $postBody array of post parameters |
||
73 | */ |
||
74 | public function setPostBody($postBody) |
||
78 | |||
79 | /** |
||
80 | * @param string $requestMethod HTTP Request method |
||
81 | */ |
||
82 | public function setRequestMethod($requestMethod) |
||
86 | |||
87 | /** |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function getExpectedType() |
||
94 | |||
95 | /** |
||
96 | * @param mixed $responseBody |
||
97 | */ |
||
98 | public function setResponseBody($responseBody) |
||
102 | |||
103 | /** |
||
104 | * @param array $responseHeaders of HTTP response headers |
||
105 | */ |
||
106 | public function setResponseHeaders($responseHeaders) |
||
110 | |||
111 | /** |
||
112 | * @return integer HTTP response code |
||
113 | */ |
||
114 | public function getHttpResponseCode() |
||
118 | |||
119 | /** |
||
120 | * @param array $requestHeaders array with request headers with keys and values |
||
121 | */ |
||
122 | public function setRequestHeaders($requestHeaders) |
||
126 | |||
127 | /** |
||
128 | * @param string $url this should be a valid HTTP URL |
||
129 | */ |
||
130 | public function setUrl($url) |
||
134 | |||
135 | /** |
||
136 | * @return mixed response body |
||
137 | */ |
||
138 | public function getResponseBody() |
||
142 | |||
143 | /** |
||
144 | * @return array HTTP Reponse headers |
||
145 | */ |
||
146 | public function getResponseHeaders() |
||
150 | |||
151 | /** |
||
152 | * @return string HTTP Request Method |
||
153 | */ |
||
154 | public function getRequestMethod() |
||
158 | |||
159 | /** |
||
160 | * @return array $requestHeaders as the headers set for this request |
||
161 | */ |
||
162 | public function getRequestHeaders() |
||
166 | |||
167 | /** |
||
168 | * @return string url return the requested url |
||
169 | */ |
||
170 | public function getUrl() |
||
174 | |||
175 | /** |
||
176 | * @return array of post body parameters |
||
177 | */ |
||
178 | public function getPostBody() |
||
182 | } |