1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Padosoft.com 2016. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Padosoft\HTTPClient; |
7
|
|
|
|
8
|
|
|
use Padosoft\HTTPClient\MethodHttpHelper; |
9
|
|
|
use GuzzleHttp\Client; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class HttpHelper |
13
|
|
|
* HTTP Helper class |
14
|
|
|
* @package Padosoft\HTTPClient |
15
|
|
|
*/ |
16
|
|
|
class HttpHelperFacade |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Response |
20
|
|
|
*/ |
21
|
|
|
protected $response; |
22
|
|
|
/** |
23
|
|
|
* @var HTTPClient |
24
|
|
|
*/ |
25
|
|
|
protected $httpclient; |
26
|
|
|
/** |
27
|
|
|
* @var \Padosoft\HTTPClient\RequestHelper |
28
|
|
|
*/ |
29
|
|
|
protected $requestHelper; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* HttpHelper constructor. |
33
|
|
|
* @param HTTPClient $httpclient |
34
|
|
|
*/ |
35
|
|
|
public function __construct(\Padosoft\HTTPClient\HTTPClient $httpclient) |
36
|
|
|
{ |
37
|
|
|
$this->httpclient = $httpclient; |
38
|
|
|
$this->requestHelper = $httpclient->requestHelper; |
|
|
|
|
39
|
|
|
$this->response = new Response(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Send HTTP Request |
44
|
|
|
* |
45
|
|
|
* @param $method |
46
|
|
|
* @param $uri |
47
|
|
|
* @param array $getParams |
48
|
|
|
* @param array $postParams |
49
|
|
|
* @param string $user |
50
|
|
|
* @param string $password |
51
|
|
|
* @param array $jsonParams |
52
|
|
|
* @param int $requesTimeout |
53
|
|
|
* @param bool $SSLVerify |
54
|
|
|
* @param array $customHeaders |
55
|
|
|
* @param string $accept |
56
|
|
|
* @param string $protocolVersion |
57
|
|
|
* @return Response |
58
|
|
|
*/ |
59
|
|
|
public static function sendSimpleRequest($method, $uri |
60
|
|
|
, array $getParams=[], array $postParams=[] |
61
|
|
|
, $user="", $password="" |
62
|
|
|
, array $jsonParams=[] |
63
|
|
|
, $requesTimeout=0, $SSLVerify=true |
64
|
|
|
, array $customHeaders=[], $accept="", $protocolVersion="" |
65
|
|
|
) |
66
|
|
|
{ |
67
|
|
|
|
68
|
|
|
$requestHelper = new RequestHelper(); |
69
|
|
|
$guzzle = new Client(); |
70
|
|
|
$httpClient = new HTTPClient($guzzle,$requestHelper); |
71
|
|
|
$httpHelper = new HttpHelper($httpClient); |
72
|
|
|
|
73
|
|
|
$response = $httpHelper->sendSimpleRequest($method, $uri |
74
|
|
|
, $getParams, $postParams |
75
|
|
|
, $user, $password |
76
|
|
|
, $jsonParams |
77
|
|
|
, $requesTimeout, $SSLVerify |
78
|
|
|
, $customHeaders, $accept, $protocolVersion); |
79
|
|
|
|
80
|
|
|
return $response; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param $uri |
85
|
|
|
* @param array $getParams |
86
|
|
|
* @param array $postParams |
87
|
|
|
* @return Response |
88
|
|
|
*/ |
89
|
|
|
public static function sendGet($uri, array $getParams=[], array $postParams=[]) |
90
|
|
|
{ |
91
|
|
|
|
92
|
|
|
$requestHelper = new RequestHelper(); |
93
|
|
|
$guzzle = new Client(); |
94
|
|
|
$httpClient = new HTTPClient($guzzle,$requestHelper); |
95
|
|
|
$httpHelper = new HttpHelper($httpClient); |
96
|
|
|
$response = $httpHelper->sendGet($uri, $getParams, $postParams); |
97
|
|
|
|
98
|
|
|
return $response; |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param $uri |
104
|
|
|
* @param array $getParams |
105
|
|
|
* @param array $postParams |
106
|
|
|
* @param $user |
107
|
|
|
* @param $password |
108
|
|
|
* @return Response |
109
|
|
|
*/ |
110
|
|
View Code Duplication |
public static function sendGetWithAuth($uri, array $getParams=[], array $postParams=[], $user, $password) |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
|
113
|
|
|
$requestHelper = new RequestHelper(); |
114
|
|
|
$guzzle = new Client(); |
115
|
|
|
$httpClient = new HTTPClient($guzzle,$requestHelper); |
116
|
|
|
$httpHelper = new HttpHelper($httpClient); |
117
|
|
|
$response = $httpHelper->sendGetWithAuth($uri, $getParams, $postParams, $user, $password); |
118
|
|
|
|
119
|
|
|
return $response; |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param $uri |
126
|
|
|
* @param array $getParams |
127
|
|
|
* @param array $postParams |
128
|
|
|
* @return Response |
129
|
|
|
*/ |
130
|
|
|
public static function sendPost($uri, array $getParams=[], array $postParams=[]) |
131
|
|
|
{ |
132
|
|
|
$requestHelper = new RequestHelper(); |
133
|
|
|
$guzzle = new Client(); |
134
|
|
|
$httpClient = new HTTPClient($guzzle,$requestHelper); |
135
|
|
|
$httpHelper = new HttpHelper($httpClient); |
136
|
|
|
$response = $httpHelper->sendPost($uri, $getParams, $postParams); |
137
|
|
|
|
138
|
|
|
return $response; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param $uri |
143
|
|
|
* @param array $getParams |
144
|
|
|
* @param array $postParams |
145
|
|
|
* @param $user |
146
|
|
|
* @param $password |
147
|
|
|
* @return Response |
148
|
|
|
*/ |
149
|
|
View Code Duplication |
public static function sendPostWithAuth($uri, array $getParams=[], array $postParams=[], $user, $password) |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
$requestHelper = new RequestHelper(); |
152
|
|
|
$guzzle = new Client(); |
153
|
|
|
$httpClient = new HTTPClient($guzzle,$requestHelper); |
154
|
|
|
$httpHelper = new HttpHelper($httpClient); |
155
|
|
|
$response = $httpHelper->sendPostWithAuth($uri, $getParams, $postParams, $user, $password); |
156
|
|
|
|
157
|
|
|
return $response; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param $uri |
162
|
|
|
* @param array $jsonParams |
163
|
|
|
* @param $user |
164
|
|
|
* @param $password |
165
|
|
|
* @return Response |
166
|
|
|
*/ |
167
|
|
|
public static function sendPostJsonWithAuth($uri, array $jsonParams=[], $user, $password) |
168
|
|
|
{ |
169
|
|
|
$requestHelper = new RequestHelper(); |
170
|
|
|
$guzzle = new Client(); |
171
|
|
|
$httpClient = new HTTPClient($guzzle,$requestHelper); |
172
|
|
|
$httpHelper = new HttpHelper($httpClient); |
173
|
|
|
$response = $httpHelper->sendPostJsonWithAuth($uri, $jsonParams, $user, $password); |
174
|
|
|
return $response; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
} |
179
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.