77
88class Request
99{
10- private string $ url ;
10+ private ? int $ connectTimeout = null ;
1111
12- private string $ method ;
12+ private array $ data = [] ;
1313
1414 private array $ headers = [];
1515
16- private array $ data = [] ;
16+ private bool $ insecure = false ;
1717
18- private bool $ rawData = false ;
18+ private ?int $ maxTimeout = null ;
19+
20+ private string $ method ;
1921
2022 private bool $ multipartFormData = false ;
2123
22- private ? string $ username = null ;
24+ private array $ guzzleOptions = [] ;
2325
2426 private ?string $ password = null ;
2527
26- private ?int $ maxTimeout = null ;
27-
28- private ?int $ connectTimeout = null ;
28+ private bool $ rawData = false ;
2929
30- private array $ options = [] ;
30+ private string $ url ;
3131
32- private bool $ insecure = false ;
32+ private ? string $ username = null ;
3333
3434 private function __construct ($ url , $ method )
3535 {
@@ -114,14 +114,14 @@ public static function create(array $data): self
114114 @[$ certificate , $ password ] = explode (': ' , $ data ['cert ' ], 2 );
115115
116116 if (isset ($ password )) {
117- $ request ->options ['cert ' ] = [$ certificate , $ password ];
117+ $ request ->guzzleOptions ['cert ' ] = [$ certificate , $ password ];
118118 } else {
119- $ request ->options ['cert ' ] = $ certificate ;
119+ $ request ->guzzleOptions ['cert ' ] = $ certificate ;
120120 }
121121 }
122122
123123 if (isset ($ data ['key ' ])) {
124- $ request ->options ['ssl_key ' ] = $ data ['key ' ];
124+ $ request ->guzzleOptions ['ssl_key ' ] = $ data ['key ' ];
125125 }
126126
127127 if ($ data ['insecure ' ]) {
@@ -131,96 +131,79 @@ public static function create(array $data): self
131131 return $ request ;
132132 }
133133
134+ public function connectTimeout (): int
135+ {
136+ return $ this ->connectTimeout ;
137+ }
138+
134139 public function data (): array
135140 {
136141 return $ this ->data ;
137142 }
138143
139- public function hasUsernameOrPassword (): bool
144+ public function hasConnectTimeout (): bool
140145 {
141- return isset ($ this ->username ) || isset ( $ this -> password );
146+ return isset ($ this ->connectTimeout );
142147 }
143148
144149 public function hasMaxTimeout (): bool
145150 {
146151 return isset ($ this ->maxTimeout );
147152 }
148153
149- public function hasConnectTimeout (): bool
154+ public function hasUsernameOrPassword (): bool
150155 {
151- return isset ($ this ->connectTimeout );
156+ return isset ($ this ->username ) || isset ( $ this -> password );
152157 }
153158
154159 public function headers (): array
155160 {
156161 return $ this ->headers ;
157162 }
158163
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
170165 {
171- return $ this ->url ;
166+ return $ this ->insecure ;
172167 }
173168
174169 public function isMultipartFormData (): bool
175170 {
176171 return $ this ->multipartFormData ;
177172 }
178173
179- public function username (): string
180- {
181- return $ this ->username ?? '' ;
182- }
183-
184- public function password (): string
174+ public function isRawData (): bool
185175 {
186- return $ this ->password ?? '' ;
176+ return $ this ->rawData ;
187177 }
188178
189179 public function maxTimeout (): int
190180 {
191181 return $ this ->maxTimeout ;
192182 }
193183
194- public function connectTimeout (): int
184+ public function method (): string
195185 {
196- return $ this ->connectTimeout ;
186+ return $ this ->method ;
197187 }
198188
199189 public function options (): array
200190 {
201- return $ this ->options ;
191+ return $ this ->guzzleOptions ;
202192 }
203193
204- public function isInsecure (): bool
194+ public function password (): string
205195 {
206- return $ this ->insecure ;
196+ return $ this ->password ?? '' ;
207197 }
208198
209- private static function convertDataType ( string $ value )
199+ public function url (): string
210200 {
211- return preg_match ( ' /^[1-9]\d*$/ ' , $ value ) ? intval ( $ value ) : $ value ;
201+ return $ this -> url ;
212202 }
213203
214- private static function parseData ( array $ data ): array
204+ public function username ( ): string
215205 {
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 ?? '' ;
224207 }
225208
226209 private static function buildUrl (array $ url ): string
@@ -237,4 +220,21 @@ private static function buildUrl(array $url): string
237220
238221 return $ output ;
239222 }
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+ }
240240}
0 commit comments