1 | <?php |
||
11 | class RequestHandler |
||
12 | { |
||
13 | /** |
||
14 | * @var mixed |
||
15 | */ |
||
16 | protected $response; |
||
17 | |||
18 | /** |
||
19 | * @var integer |
||
20 | */ |
||
21 | protected $httpCode; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $httpErrors = [ |
||
27 | 301 => 'Moved permanently', |
||
28 | 400 => 'Bad request', |
||
29 | 401 => 'Unauthorized', |
||
30 | 403 => 'Forbidden', |
||
31 | 404 => 'Not found', |
||
32 | 500 => 'Internal server error', |
||
33 | 502 => 'Bad gateway', |
||
34 | 503 => 'Service unavailable' |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $successHttpCodes = [ |
||
41 | 200, 204 |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $subdomain; |
||
48 | |||
49 | /** |
||
50 | * @param string $link |
||
51 | * @param array $fields |
||
52 | * @param string $contentType |
||
53 | * @param string $requestType |
||
54 | */ |
||
55 | 3 | public function performRequest($link, array $fields, $contentType = 'application/json', $requestType = 'POST') |
|
76 | |||
77 | /** |
||
78 | * @return bool |
||
79 | */ |
||
80 | 4 | public function getResponse() |
|
90 | |||
91 | /** |
||
92 | * @param $subdomain string |
||
93 | */ |
||
94 | 4 | public function setSubdomain($subdomain) |
|
98 | |||
99 | /** |
||
100 | * @return string |
||
101 | */ |
||
102 | 1 | public function getSubdomain() |
|
106 | |||
107 | /** |
||
108 | * Encoding response from json, throw exception in case of wrong http code |
||
109 | */ |
||
110 | 3 | protected function encodeResponse() |
|
122 | |||
123 | /** |
||
124 | * @return string |
||
125 | */ |
||
126 | 3 | protected function getCookiePath() |
|
130 | |||
131 | /** |
||
132 | * @param array $fields |
||
133 | * @param $contentType |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 3 | private function getStringFields(array $fields, $contentType) |
|
145 | } |