@@ -70,6 +70,9 @@ class Curl
70
70
/** @var null|resource|false */
71
71
protected $ curl = null ;
72
72
73
+ /** @var null|bool|string */
74
+ protected $ exec = null ;
75
+
73
76
public function __construct ()
74
77
{
75
78
if (!\extension_loaded ('curl ' )){
@@ -241,6 +244,19 @@ public function getError(): ?string
241
244
return empty ($ this ->error ) ? null : $ this ->error ;
242
245
}
243
246
247
+ /**
248
+ * @param string $filePath
249
+ * @return false|int
250
+ */
251
+ public function save (string $ filePath )
252
+ {
253
+ $ content = $ this ->getResponse ('body ' );
254
+ if (empty ($ content )) {
255
+ return false ;
256
+ }
257
+ return @\file_put_contents ($ filePath , $ content );
258
+ }
259
+
244
260
/**
245
261
* @param int|string $key
246
262
* @param mixed $value
@@ -271,7 +287,7 @@ public function handler(): bool
271
287
if (!empty ($ this ->options )){
272
288
\curl_setopt_array ($ this ->curl , $ this ->options );
273
289
}
274
- $ res = \curl_exec ($ this ->curl );
290
+ $ this -> exec = \curl_exec ($ this ->curl );
275
291
$ this ->getInfo = \curl_getinfo ($ this ->curl );
276
292
$ this ->error = \curl_error ($ this ->curl );
277
293
}catch (\Exception $ e ) {
@@ -285,20 +301,20 @@ public function handler(): bool
285
301
]);
286
302
\curl_reset ($ this ->curl );
287
303
\curl_close ($ this ->curl );
304
+ $ this ->curl = null ;
288
305
}
289
- return $ res !== FALSE ;
306
+ return ! empty ( $ this -> exec ) ;
290
307
}
291
308
292
-
293
309
private function curlOptionsPrepare (): void
294
310
{
295
311
if (\defined ('CURLOPT_PROTOCOLS ' )){
296
312
$ this ->addCurlOption (\CURLOPT_PROTOCOLS , (\CURLPROTO_HTTP | \CURLPROTO_HTTPS ))
297
313
->addCurlOption (\CURLOPT_REDIR_PROTOCOLS , (\CURLPROTO_HTTP | \CURLPROTO_HTTPS ));
298
314
}
299
315
$ this ->addCurlOption (\CURLOPT_HEADER , false )
300
- ->addCurlOption (\CURLOPT_RETURNTRANSFER , false )
301
316
->addCurlOption (\CURLOPT_FAILONERROR , false );
317
+ $ this ->addCurlOption (\CURLOPT_RETURNTRANSFER , false );
302
318
303
319
$ canFollow = $ this ->canFollow && $ this ->allowRedirects ;
304
320
$ this ->addCurlOption (\CURLOPT_FOLLOWLOCATION , $ canFollow )
0 commit comments