7
7
8
8
class Request
9
9
{
10
- private string $ url ;
10
+ private ? int $ connectTimeout = null ;
11
11
12
- private string $ method ;
12
+ private array $ data = [] ;
13
13
14
14
private array $ headers = [];
15
15
16
- private array $ data = [] ;
16
+ private bool $ insecure = false ;
17
17
18
- private bool $ rawData = false ;
18
+ private ?int $ maxTimeout = null ;
19
+
20
+ private string $ method ;
19
21
20
22
private bool $ multipartFormData = false ;
21
23
22
- private ? string $ username = null ;
24
+ private array $ guzzleOptions = [] ;
23
25
24
26
private ?string $ password = null ;
25
27
26
- private ?int $ maxTimeout = null ;
27
-
28
- private ?int $ connectTimeout = null ;
28
+ private bool $ rawData = false ;
29
29
30
- private array $ options = [] ;
30
+ private string $ url ;
31
31
32
- private bool $ insecure = false ;
32
+ private ? string $ username = null ;
33
33
34
34
private function __construct ($ url , $ method )
35
35
{
@@ -114,14 +114,14 @@ public static function create(array $data): self
114
114
@[$ certificate , $ password ] = explode (': ' , $ data ['cert ' ], 2 );
115
115
116
116
if (isset ($ password )) {
117
- $ request ->options ['cert ' ] = [$ certificate , $ password ];
117
+ $ request ->guzzleOptions ['cert ' ] = [$ certificate , $ password ];
118
118
} else {
119
- $ request ->options ['cert ' ] = $ certificate ;
119
+ $ request ->guzzleOptions ['cert ' ] = $ certificate ;
120
120
}
121
121
}
122
122
123
123
if (isset ($ data ['key ' ])) {
124
- $ request ->options ['ssl_key ' ] = $ data ['key ' ];
124
+ $ request ->guzzleOptions ['ssl_key ' ] = $ data ['key ' ];
125
125
}
126
126
127
127
if ($ data ['insecure ' ]) {
@@ -131,96 +131,79 @@ public static function create(array $data): self
131
131
return $ request ;
132
132
}
133
133
134
+ public function connectTimeout (): int
135
+ {
136
+ return $ this ->connectTimeout ;
137
+ }
138
+
134
139
public function data (): array
135
140
{
136
141
return $ this ->data ;
137
142
}
138
143
139
- public function hasUsernameOrPassword (): bool
144
+ public function hasConnectTimeout (): bool
140
145
{
141
- return isset ($ this ->username ) || isset ( $ this -> password );
146
+ return isset ($ this ->connectTimeout );
142
147
}
143
148
144
149
public function hasMaxTimeout (): bool
145
150
{
146
151
return isset ($ this ->maxTimeout );
147
152
}
148
153
149
- public function hasConnectTimeout (): bool
154
+ public function hasUsernameOrPassword (): bool
150
155
{
151
- return isset ($ this ->connectTimeout );
156
+ return isset ($ this ->username ) || isset ( $ this -> password );
152
157
}
153
158
154
159
public function headers (): array
155
160
{
156
161
return $ this ->headers ;
157
162
}
158
163
159
- public function isRawData (): bool
160
- {
161
- return $ this ->rawData ;
162
- }
163
-
164
- public function method (): string
165
- {
166
- return $ this ->method ;
167
- }
168
-
169
- public function url (): string
164
+ public function isInsecure (): bool
170
165
{
171
- return $ this ->url ;
166
+ return $ this ->insecure ;
172
167
}
173
168
174
169
public function isMultipartFormData (): bool
175
170
{
176
171
return $ this ->multipartFormData ;
177
172
}
178
173
179
- public function username (): string
180
- {
181
- return $ this ->username ?? '' ;
182
- }
183
-
184
- public function password (): string
174
+ public function isRawData (): bool
185
175
{
186
- return $ this ->password ?? '' ;
176
+ return $ this ->rawData ;
187
177
}
188
178
189
179
public function maxTimeout (): int
190
180
{
191
181
return $ this ->maxTimeout ;
192
182
}
193
183
194
- public function connectTimeout (): int
184
+ public function method (): string
195
185
{
196
- return $ this ->connectTimeout ;
186
+ return $ this ->method ;
197
187
}
198
188
199
189
public function options (): array
200
190
{
201
- return $ this ->options ;
191
+ return $ this ->guzzleOptions ;
202
192
}
203
193
204
- public function isInsecure (): bool
194
+ public function password (): string
205
195
{
206
- return $ this ->insecure ;
196
+ return $ this ->password ?? '' ;
207
197
}
208
198
209
- private static function convertDataType ( string $ value )
199
+ public function url (): string
210
200
{
211
- return preg_match ( ' /^[1-9]\d*$/ ' , $ value ) ? intval ( $ value ) : $ value ;
201
+ return $ this -> url ;
212
202
}
213
203
214
- private static function parseData ( array $ data ): array
204
+ public function username ( ): string
215
205
{
216
- parse_str (implode ('& ' , $ data ), $ data );
217
- array_walk_recursive ($ data , function (&$ value ) {
218
- if (is_string ($ value )) {
219
- $ value = self ::convertDataType ($ value );
220
- }
221
- });
222
-
223
- return $ data ;
206
+ return $ this ->username ?? '' ;
224
207
}
225
208
226
209
private static function buildUrl (array $ url ): string
@@ -237,4 +220,21 @@ private static function buildUrl(array $url): string
237
220
238
221
return $ output ;
239
222
}
223
+
224
+ private static function convertDataType (string $ value )
225
+ {
226
+ return preg_match ('/^[1-9]\d*$/ ' , $ value ) ? intval ($ value ) : $ value ;
227
+ }
228
+
229
+ private static function parseData (array $ data ): array
230
+ {
231
+ parse_str (implode ('& ' , $ data ), $ data );
232
+ array_walk_recursive ($ data , function (&$ value ) {
233
+ if (is_string ($ value )) {
234
+ $ value = self ::convertDataType ($ value );
235
+ }
236
+ });
237
+
238
+ return $ data ;
239
+ }
240
240
}
0 commit comments