1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author: stev leibelt <[email protected]> |
4
|
|
|
* @since: 2015-12-09 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Net\Bazzline\Component\Curl; |
8
|
|
|
|
9
|
|
|
class Response |
10
|
|
|
{ |
11
|
|
|
const ARRAY_KEY_CONTENT = 'content'; |
12
|
|
|
const ARRAY_KEY_CONTENT_TYPE = 'content_type'; |
13
|
|
|
const ARRAY_KEY_ERROR = 'error'; |
14
|
|
|
const ARRAY_KEY_ERROR_CODE = 'error_code'; |
15
|
|
|
const ARRAY_KEY_STATUS_CODE = 'status_code'; |
16
|
|
|
|
17
|
|
|
/** @var null|mixed */ |
18
|
|
|
private $content; |
19
|
|
|
|
20
|
|
|
/** @var null|string */ |
21
|
|
|
private $contentType; |
22
|
|
|
|
23
|
|
|
/** @var array */ |
24
|
|
|
private $headerLines; |
25
|
|
|
|
26
|
|
|
/** @var null|string */ |
27
|
|
|
private $error; |
28
|
|
|
|
29
|
|
|
/** @var null|int */ |
30
|
|
|
private $errorCode; |
31
|
|
|
|
32
|
|
|
/** @var null|int */ |
33
|
|
|
private $statusCode; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param mixed $content |
37
|
|
|
* @param string $contentType |
38
|
|
|
* @param array $headerLines |
39
|
|
|
* @param string $error |
40
|
|
|
* @param int $errorCode |
41
|
|
|
* @param int $statusCode |
42
|
|
|
*/ |
43
|
|
|
public function __construct($content, $contentType, array $headerLines, $error, $errorCode, $statusCode) |
44
|
|
|
{ |
45
|
|
|
$this->content = $content; |
46
|
|
|
$this->contentType = $contentType; |
47
|
|
|
$this->headerLines = $headerLines; |
48
|
|
|
$this->error = $error; |
49
|
|
|
$this->errorCode = $errorCode; |
50
|
|
|
$this->statusCode = $statusCode; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return null|mixed |
55
|
|
|
*/ |
56
|
|
|
public function content() |
57
|
|
|
{ |
58
|
|
|
return $this->content; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return null|string |
63
|
|
|
*/ |
64
|
|
|
public function contentType() |
65
|
|
|
{ |
66
|
|
|
return $this->contentType; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $prefix |
71
|
|
|
* @return null|string |
72
|
|
|
*/ |
73
|
|
|
public function headerLine($prefix) |
74
|
|
|
{ |
75
|
|
|
return ( |
76
|
|
|
(isset($this->headerLines[$prefix])) |
77
|
|
|
? $this->headerLines[$prefix] |
78
|
|
|
: null |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
|
public function headerLines() |
86
|
|
|
{ |
87
|
|
|
return $this->headerLines; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return null|string |
92
|
|
|
*/ |
93
|
|
|
public function error() |
94
|
|
|
{ |
95
|
|
|
return $this->error; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return null|int |
100
|
|
|
* @see: http://curl.haxx.se/libcurl/c/libcurl-errors.html |
101
|
|
|
*/ |
102
|
|
|
public function errorCode() |
103
|
|
|
{ |
104
|
|
|
return $this->errorCode; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return null|int |
109
|
|
|
*/ |
110
|
|
|
public function statusCode() |
111
|
|
|
{ |
112
|
|
|
return $this->statusCode; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
public function convertIntoAnArray() |
119
|
|
|
{ |
120
|
|
|
return array( |
121
|
|
|
self::ARRAY_KEY_CONTENT => $this->content, |
122
|
|
|
self::ARRAY_KEY_CONTENT_TYPE => $this->contentType, |
123
|
|
|
self::ARRAY_KEY_ERROR => $this->error, |
124
|
|
|
self::ARRAY_KEY_ERROR_CODE => $this->errorCode, |
125
|
|
|
self::ARRAY_KEY_STATUS_CODE => $this->statusCode |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|