@@ -15,80 +15,80 @@ |
||
15 | 15 | |
16 | 16 | class Response |
17 | 17 | { |
18 | - public |
|
19 | - $code, |
|
20 | - $errorCode, |
|
21 | - $error, |
|
22 | - $header, |
|
23 | - $body, |
|
24 | - /** |
|
25 | - * @var Request |
|
26 | - */ |
|
27 | - $request, |
|
28 | - $contentType, |
|
29 | - $charset, |
|
30 | - $duration, |
|
31 | - $info; |
|
32 | - protected function __construct() |
|
33 | - { |
|
34 | - } |
|
18 | + public |
|
19 | + $code, |
|
20 | + $errorCode, |
|
21 | + $error, |
|
22 | + $header, |
|
23 | + $body, |
|
24 | + /** |
|
25 | + * @var Request |
|
26 | + */ |
|
27 | + $request, |
|
28 | + $contentType, |
|
29 | + $charset, |
|
30 | + $duration, |
|
31 | + $info; |
|
32 | + protected function __construct() |
|
33 | + { |
|
34 | + } |
|
35 | 35 | |
36 | - public static function create(Request $request, $body, $info, $errorCode, $error){ |
|
37 | - $self = new self; |
|
38 | - $self->request = $request; |
|
39 | - $self->body = $body; |
|
40 | - $self->info = $info; |
|
41 | - $self->errorCode = $errorCode; |
|
42 | - $self->error = $error; |
|
43 | - $self->parse(); |
|
44 | - $self->check(); |
|
45 | - return $self; |
|
46 | - } |
|
47 | - public function check(){ |
|
36 | + public static function create(Request $request, $body, $info, $errorCode, $error){ |
|
37 | + $self = new self; |
|
38 | + $self->request = $request; |
|
39 | + $self->body = $body; |
|
40 | + $self->info = $info; |
|
41 | + $self->errorCode = $errorCode; |
|
42 | + $self->error = $error; |
|
43 | + $self->parse(); |
|
44 | + $self->check(); |
|
45 | + return $self; |
|
46 | + } |
|
47 | + public function check(){ |
|
48 | 48 | |
49 | - } |
|
50 | - public function parse(){ |
|
51 | - if($this->body && $this->request->getIni('header')){//has header |
|
52 | - $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
|
53 | - $this->body = substr($this->body, $this->info['header_size']); |
|
54 | - $headers = explode(PHP_EOL, $headers); |
|
55 | - array_shift($headers); // HTTP HEADER |
|
56 | - foreach($headers as $h) { |
|
57 | - if(false !== strpos($h, ':')) |
|
58 | - list($k, $v) = explode(':', $h, 2); |
|
59 | - else |
|
60 | - list($k, $v) = array($h,''); |
|
49 | + } |
|
50 | + public function parse(){ |
|
51 | + if($this->body && $this->request->getIni('header')){//has header |
|
52 | + $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
|
53 | + $this->body = substr($this->body, $this->info['header_size']); |
|
54 | + $headers = explode(PHP_EOL, $headers); |
|
55 | + array_shift($headers); // HTTP HEADER |
|
56 | + foreach($headers as $h) { |
|
57 | + if(false !== strpos($h, ':')) |
|
58 | + list($k, $v) = explode(':', $h, 2); |
|
59 | + else |
|
60 | + list($k, $v) = array($h,''); |
|
61 | 61 | |
62 | - $this->header[trim($k)] = trim($v); |
|
63 | - } |
|
64 | - } |
|
65 | - $this->code = $this->info['http_code']; |
|
66 | - $this->duration = $this->info['total_time']; |
|
67 | - $this->contentType = $this->info['content_type']; |
|
68 | - $content_type = isset($this->info['content_type']) ? $this->info['content_type'] : ''; |
|
69 | - $content_type = explode(';', $content_type); |
|
70 | - $this->contentType = $content_type[0]; |
|
71 | - if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
|
72 | - list( , $this->charset) = explode('=', $content_type[1]); |
|
73 | - } |
|
74 | - } |
|
62 | + $this->header[trim($k)] = trim($v); |
|
63 | + } |
|
64 | + } |
|
65 | + $this->code = $this->info['http_code']; |
|
66 | + $this->duration = $this->info['total_time']; |
|
67 | + $this->contentType = $this->info['content_type']; |
|
68 | + $content_type = isset($this->info['content_type']) ? $this->info['content_type'] : ''; |
|
69 | + $content_type = explode(';', $content_type); |
|
70 | + $this->contentType = $content_type[0]; |
|
71 | + if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
|
72 | + list( , $this->charset) = explode('=', $content_type[1]); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Status Code Definitions |
|
78 | - * |
|
79 | - * Informational 1xx |
|
80 | - * Successful 2xx |
|
81 | - * Redirection 3xx |
|
82 | - * Client Error 4xx |
|
83 | - * Server Error 5xx |
|
84 | - * |
|
85 | - * http://pretty-rfc.herokuapp.com/RFC2616#status.codes |
|
86 | - * |
|
87 | - * @return bool Did we receive a 4xx or 5xx? |
|
88 | - */ |
|
89 | - public function hasErrors() |
|
90 | - { |
|
91 | - return $this->code == 0 || $this->code >= 400; |
|
92 | - } |
|
76 | + /** |
|
77 | + * Status Code Definitions |
|
78 | + * |
|
79 | + * Informational 1xx |
|
80 | + * Successful 2xx |
|
81 | + * Redirection 3xx |
|
82 | + * Client Error 4xx |
|
83 | + * Server Error 5xx |
|
84 | + * |
|
85 | + * http://pretty-rfc.herokuapp.com/RFC2616#status.codes |
|
86 | + * |
|
87 | + * @return bool Did we receive a 4xx or 5xx? |
|
88 | + */ |
|
89 | + public function hasErrors() |
|
90 | + { |
|
91 | + return $this->code == 0 || $this->code >= 400; |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | \ No newline at end of file |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | } |
35 | 35 | |
36 | - public static function create(Request $request, $body, $info, $errorCode, $error){ |
|
36 | + public static function create(Request $request, $body, $info, $errorCode, $error) { |
|
37 | 37 | $self = new self; |
38 | 38 | $self->request = $request; |
39 | 39 | $self->body = $body; |
@@ -44,20 +44,20 @@ discard block |
||
44 | 44 | $self->check(); |
45 | 45 | return $self; |
46 | 46 | } |
47 | - public function check(){ |
|
47 | + public function check() { |
|
48 | 48 | |
49 | 49 | } |
50 | - public function parse(){ |
|
51 | - if($this->body && $this->request->getIni('header')){//has header |
|
50 | + public function parse() { |
|
51 | + if ($this->body && $this->request->getIni('header')) {//has header |
|
52 | 52 | $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
53 | 53 | $this->body = substr($this->body, $this->info['header_size']); |
54 | 54 | $headers = explode(PHP_EOL, $headers); |
55 | 55 | array_shift($headers); // HTTP HEADER |
56 | - foreach($headers as $h) { |
|
57 | - if(false !== strpos($h, ':')) |
|
56 | + foreach ($headers as $h) { |
|
57 | + if (false !== strpos($h, ':')) |
|
58 | 58 | list($k, $v) = explode(':', $h, 2); |
59 | 59 | else |
60 | - list($k, $v) = array($h,''); |
|
60 | + list($k, $v) = array($h, ''); |
|
61 | 61 | |
62 | 62 | $this->header[trim($k)] = trim($v); |
63 | 63 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $content_type = explode(';', $content_type); |
70 | 70 | $this->contentType = $content_type[0]; |
71 | 71 | if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
72 | - list( , $this->charset) = explode('=', $content_type[1]); |
|
72 | + list(, $this->charset) = explode('=', $content_type[1]); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 |