|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2015 Dirk Groenen |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Dirk Groenen <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace DirkGroenen\Pinterest\Transport; |
|
12
|
|
|
|
|
13
|
|
|
use DirkGroenen\Pinterest\Utils\CurlBuilder; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @property array $page |
|
17
|
|
|
* @property array $data |
|
18
|
|
|
* @property string $message |
|
19
|
|
|
*/ |
|
20
|
|
|
class Response { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Contains the raw response |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $response; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Used curl instance |
|
31
|
|
|
* |
|
32
|
|
|
* @var curl |
|
33
|
|
|
*/ |
|
34
|
|
|
private $curl; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructor |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $response |
|
40
|
|
|
* @param CurlBuilder $curl |
|
41
|
|
|
* @param curl $curl |
|
42
|
|
|
*/ |
|
43
|
33 |
|
public function __construct($response, CurlBuilder $curl) |
|
44
|
|
|
{ |
|
45
|
33 |
|
$this->response = $response; |
|
46
|
33 |
|
$this->curl = $curl; |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
33 |
|
if (is_string($response)) { |
|
49
|
33 |
|
$this->response = $this->decodeString($response); |
|
|
|
|
|
|
50
|
33 |
|
} |
|
51
|
33 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Decode the string to an array |
|
55
|
|
|
* |
|
56
|
|
|
* @access private |
|
57
|
|
|
* @param string $response |
|
58
|
|
|
* @return array |
|
59
|
|
|
*/ |
|
60
|
33 |
|
private function decodeString($response) |
|
61
|
|
|
{ |
|
62
|
33 |
|
return json_decode($response, true); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Return the requested key data |
|
67
|
|
|
* |
|
68
|
|
|
* @access public |
|
69
|
|
|
* @param string $key |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
27 |
|
public function __get($key) |
|
73
|
|
|
{ |
|
74
|
27 |
|
return isset($this->response[$key]) ? $this->response[$key] : []; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Return if the key is set |
|
79
|
|
|
* |
|
80
|
|
|
* @access public |
|
81
|
|
|
* @param string $key |
|
82
|
|
|
* @return boolean |
|
83
|
|
|
*/ |
|
84
|
18 |
|
public function __isset($key) |
|
85
|
|
|
{ |
|
86
|
18 |
|
return isset($this->response[$key]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Returns the error message which should normaly |
|
91
|
|
|
* by located in the response->message key, but can |
|
92
|
|
|
* also be localed in the response->error key. |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function getMessage() |
|
97
|
|
|
{ |
|
98
|
1 |
|
return (isset($this->message)) ? $this->message : $this->error; |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the response code from the request |
|
103
|
|
|
* |
|
104
|
|
|
* @access public |
|
105
|
|
|
* @return int |
|
106
|
|
|
*/ |
|
107
|
33 |
|
public function getResponseCode() |
|
108
|
|
|
{ |
|
109
|
33 |
|
return $this->curl->getInfo(CURLINFO_HTTP_CODE); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..