@@ -25,161 +25,161 @@ |
||
25 | 25 | |
26 | 26 | class Result { |
27 | 27 | |
28 | - protected $error; |
|
29 | - protected $message; |
|
30 | - protected $headers; |
|
31 | - protected $curlInfo; |
|
32 | - protected $body; |
|
33 | - protected $reasonPhrases = array( |
|
34 | - // INFORMATIONAL CODES |
|
35 | - 100 => 'Continue', |
|
36 | - 101 => 'Switching Protocols', |
|
37 | - 102 => 'Processing', |
|
38 | - // SUCCESS CODES |
|
39 | - 200 => 'OK', |
|
40 | - 201 => 'Created', |
|
41 | - 202 => 'Accepted', |
|
42 | - 203 => 'Non-Authoritative Information', |
|
43 | - 204 => 'No Content', |
|
44 | - 205 => 'Reset Content', |
|
45 | - 206 => 'Partial Content', |
|
46 | - 207 => 'Multi-status', |
|
47 | - 208 => 'Already Reported', |
|
48 | - // REDIRECTION CODES |
|
49 | - 300 => 'Multiple Choices', |
|
50 | - 301 => 'Moved Permanently', |
|
51 | - 302 => 'Found', |
|
52 | - 303 => 'See Other', |
|
53 | - 304 => 'Not Modified', |
|
54 | - 305 => 'Use Proxy', |
|
55 | - 306 => 'Switch Proxy', // Deprecated |
|
56 | - 307 => 'Temporary Redirect', |
|
57 | - // CLIENT ERROR |
|
58 | - 400 => 'Bad Request', |
|
59 | - 401 => 'Unauthorized', |
|
60 | - 402 => 'Payment Required', |
|
61 | - 403 => 'Forbidden', |
|
62 | - 404 => 'Not Found', |
|
63 | - 405 => 'Method Not Allowed', |
|
64 | - 406 => 'Not Acceptable', |
|
65 | - 407 => 'Proxy Authentication Required', |
|
66 | - 408 => 'Request Time-out', |
|
67 | - 409 => 'Conflict', |
|
68 | - 410 => 'Gone', |
|
69 | - 411 => 'Length Required', |
|
70 | - 412 => 'Precondition Failed', |
|
71 | - 413 => 'Request Entity Too Large', |
|
72 | - 414 => 'Request-URI Too Large', |
|
73 | - 415 => 'Unsupported Media Type', |
|
74 | - 416 => 'Requested range not satisfiable', |
|
75 | - 417 => 'Expectation Failed', |
|
76 | - 418 => 'I\'m a teapot', |
|
77 | - 422 => 'Unprocessable Entity', |
|
78 | - 423 => 'Locked', |
|
79 | - 424 => 'Failed Dependency', |
|
80 | - 425 => 'Unordered Collection', |
|
81 | - 426 => 'Upgrade Required', |
|
82 | - 428 => 'Precondition Required', |
|
83 | - 429 => 'Too Many Requests', |
|
84 | - 431 => 'Request Header Fields Too Large', |
|
85 | - // SERVER ERROR |
|
86 | - 500 => 'Internal Server Error', |
|
87 | - 501 => 'Not Implemented', |
|
88 | - 502 => 'Bad Gateway', |
|
89 | - 503 => 'Service Unavailable', |
|
90 | - 504 => 'Gateway Time-out', |
|
91 | - 505 => 'HTTP Version not supported', |
|
92 | - 506 => 'Variant Also Negotiates', |
|
93 | - 507 => 'Insufficient Storage', |
|
94 | - 508 => 'Loop Detected', |
|
95 | - 511 => 'Network Authentication Required' |
|
96 | - ); |
|
97 | - |
|
98 | - public function __construct($body, $headers, $curlInfo) |
|
99 | - { |
|
100 | - $this->body = $body; |
|
101 | - $this->headers = $headers; |
|
102 | - $this->curlInfo = $curlInfo; |
|
103 | - } |
|
104 | - |
|
105 | - public function isError () |
|
106 | - { |
|
107 | - return isset($this->getResponseObject()->errors) && $this->getResponseObject()->errors; |
|
108 | - } |
|
28 | + protected $error; |
|
29 | + protected $message; |
|
30 | + protected $headers; |
|
31 | + protected $curlInfo; |
|
32 | + protected $body; |
|
33 | + protected $reasonPhrases = array( |
|
34 | + // INFORMATIONAL CODES |
|
35 | + 100 => 'Continue', |
|
36 | + 101 => 'Switching Protocols', |
|
37 | + 102 => 'Processing', |
|
38 | + // SUCCESS CODES |
|
39 | + 200 => 'OK', |
|
40 | + 201 => 'Created', |
|
41 | + 202 => 'Accepted', |
|
42 | + 203 => 'Non-Authoritative Information', |
|
43 | + 204 => 'No Content', |
|
44 | + 205 => 'Reset Content', |
|
45 | + 206 => 'Partial Content', |
|
46 | + 207 => 'Multi-status', |
|
47 | + 208 => 'Already Reported', |
|
48 | + // REDIRECTION CODES |
|
49 | + 300 => 'Multiple Choices', |
|
50 | + 301 => 'Moved Permanently', |
|
51 | + 302 => 'Found', |
|
52 | + 303 => 'See Other', |
|
53 | + 304 => 'Not Modified', |
|
54 | + 305 => 'Use Proxy', |
|
55 | + 306 => 'Switch Proxy', // Deprecated |
|
56 | + 307 => 'Temporary Redirect', |
|
57 | + // CLIENT ERROR |
|
58 | + 400 => 'Bad Request', |
|
59 | + 401 => 'Unauthorized', |
|
60 | + 402 => 'Payment Required', |
|
61 | + 403 => 'Forbidden', |
|
62 | + 404 => 'Not Found', |
|
63 | + 405 => 'Method Not Allowed', |
|
64 | + 406 => 'Not Acceptable', |
|
65 | + 407 => 'Proxy Authentication Required', |
|
66 | + 408 => 'Request Time-out', |
|
67 | + 409 => 'Conflict', |
|
68 | + 410 => 'Gone', |
|
69 | + 411 => 'Length Required', |
|
70 | + 412 => 'Precondition Failed', |
|
71 | + 413 => 'Request Entity Too Large', |
|
72 | + 414 => 'Request-URI Too Large', |
|
73 | + 415 => 'Unsupported Media Type', |
|
74 | + 416 => 'Requested range not satisfiable', |
|
75 | + 417 => 'Expectation Failed', |
|
76 | + 418 => 'I\'m a teapot', |
|
77 | + 422 => 'Unprocessable Entity', |
|
78 | + 423 => 'Locked', |
|
79 | + 424 => 'Failed Dependency', |
|
80 | + 425 => 'Unordered Collection', |
|
81 | + 426 => 'Upgrade Required', |
|
82 | + 428 => 'Precondition Required', |
|
83 | + 429 => 'Too Many Requests', |
|
84 | + 431 => 'Request Header Fields Too Large', |
|
85 | + // SERVER ERROR |
|
86 | + 500 => 'Internal Server Error', |
|
87 | + 501 => 'Not Implemented', |
|
88 | + 502 => 'Bad Gateway', |
|
89 | + 503 => 'Service Unavailable', |
|
90 | + 504 => 'Gateway Time-out', |
|
91 | + 505 => 'HTTP Version not supported', |
|
92 | + 506 => 'Variant Also Negotiates', |
|
93 | + 507 => 'Insufficient Storage', |
|
94 | + 508 => 'Loop Detected', |
|
95 | + 511 => 'Network Authentication Required' |
|
96 | + ); |
|
97 | + |
|
98 | + public function __construct($body, $headers, $curlInfo) |
|
99 | + { |
|
100 | + $this->body = $body; |
|
101 | + $this->headers = $headers; |
|
102 | + $this->curlInfo = $curlInfo; |
|
103 | + } |
|
104 | + |
|
105 | + public function isError () |
|
106 | + { |
|
107 | + return isset($this->getResponseObject()->errors) && $this->getResponseObject()->errors; |
|
108 | + } |
|
109 | 109 | |
110 | - public function getDescription () |
|
111 | - { |
|
112 | - return $this->getResponseObject()->description; |
|
113 | - } |
|
114 | - |
|
115 | - public function getHeaders() |
|
116 | - { |
|
117 | - return $this->headers; |
|
118 | - } |
|
119 | - |
|
120 | - public function getResponse() |
|
121 | - { |
|
122 | - return $this->body; |
|
123 | - } |
|
124 | - |
|
125 | - public function getResponseObject() |
|
126 | - { |
|
127 | - return json_decode($this->body); |
|
128 | - } |
|
129 | - |
|
130 | - public function getResponseArray () |
|
131 | - { |
|
132 | - return json_decode($this->body, true); |
|
133 | - } |
|
134 | - |
|
135 | - public function getResponseCode() |
|
136 | - { |
|
137 | - return $this->curlInfo['http_code']; |
|
138 | - } |
|
139 | - |
|
140 | - public function getReasonPhrase() |
|
141 | - { |
|
142 | - return $this->reasonPhrases[$this->curlInfo['http_code']]; |
|
143 | - } |
|
144 | - |
|
145 | - public function getContentType() |
|
146 | - { |
|
147 | - return $this->curlInfo['content_type']; |
|
148 | - } |
|
149 | - |
|
150 | - public function isOk() |
|
151 | - { |
|
152 | - return ($this->curlInfo['http_code'] === 200); |
|
153 | - } |
|
154 | - |
|
155 | - public function isSuccess() |
|
156 | - { |
|
157 | - return (200 <= $this->curlInfo['http_code'] && 300 > $this->curlInfo['http_code']); |
|
158 | - } |
|
159 | - |
|
160 | - public function isNotFound() |
|
161 | - { |
|
162 | - return ($this->curlInfo['http_code'] === 404); |
|
163 | - } |
|
164 | - |
|
165 | - public function isInformational() |
|
166 | - { |
|
167 | - return ($this->curlInfo['http_code'] >= 100 && $this->curlInfo['http_code'] < 200); |
|
168 | - } |
|
169 | - |
|
170 | - public function isRedirect() |
|
171 | - { |
|
172 | - return (300 <= $this->curlInfo['http_code'] && 400 > $this->curlInfo['http_code']); |
|
173 | - } |
|
174 | - |
|
175 | - public function isClientError() |
|
176 | - { |
|
177 | - return ($this->curlInfo['http_code'] < 500 && $this->curlInfo['http_code'] >= 400); |
|
178 | - } |
|
179 | - |
|
180 | - public function isServerError() |
|
181 | - { |
|
182 | - return (500 <= $this->curlInfo['http_code'] && 600 > $this->curlInfo['http_code']); |
|
183 | - } |
|
110 | + public function getDescription () |
|
111 | + { |
|
112 | + return $this->getResponseObject()->description; |
|
113 | + } |
|
114 | + |
|
115 | + public function getHeaders() |
|
116 | + { |
|
117 | + return $this->headers; |
|
118 | + } |
|
119 | + |
|
120 | + public function getResponse() |
|
121 | + { |
|
122 | + return $this->body; |
|
123 | + } |
|
124 | + |
|
125 | + public function getResponseObject() |
|
126 | + { |
|
127 | + return json_decode($this->body); |
|
128 | + } |
|
129 | + |
|
130 | + public function getResponseArray () |
|
131 | + { |
|
132 | + return json_decode($this->body, true); |
|
133 | + } |
|
134 | + |
|
135 | + public function getResponseCode() |
|
136 | + { |
|
137 | + return $this->curlInfo['http_code']; |
|
138 | + } |
|
139 | + |
|
140 | + public function getReasonPhrase() |
|
141 | + { |
|
142 | + return $this->reasonPhrases[$this->curlInfo['http_code']]; |
|
143 | + } |
|
144 | + |
|
145 | + public function getContentType() |
|
146 | + { |
|
147 | + return $this->curlInfo['content_type']; |
|
148 | + } |
|
149 | + |
|
150 | + public function isOk() |
|
151 | + { |
|
152 | + return ($this->curlInfo['http_code'] === 200); |
|
153 | + } |
|
154 | + |
|
155 | + public function isSuccess() |
|
156 | + { |
|
157 | + return (200 <= $this->curlInfo['http_code'] && 300 > $this->curlInfo['http_code']); |
|
158 | + } |
|
159 | + |
|
160 | + public function isNotFound() |
|
161 | + { |
|
162 | + return ($this->curlInfo['http_code'] === 404); |
|
163 | + } |
|
164 | + |
|
165 | + public function isInformational() |
|
166 | + { |
|
167 | + return ($this->curlInfo['http_code'] >= 100 && $this->curlInfo['http_code'] < 200); |
|
168 | + } |
|
169 | + |
|
170 | + public function isRedirect() |
|
171 | + { |
|
172 | + return (300 <= $this->curlInfo['http_code'] && 400 > $this->curlInfo['http_code']); |
|
173 | + } |
|
174 | + |
|
175 | + public function isClientError() |
|
176 | + { |
|
177 | + return ($this->curlInfo['http_code'] < 500 && $this->curlInfo['http_code'] >= 400); |
|
178 | + } |
|
179 | + |
|
180 | + public function isServerError() |
|
181 | + { |
|
182 | + return (500 <= $this->curlInfo['http_code'] && 600 > $this->curlInfo['http_code']); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | } |