@@ -157,6 +157,7 @@ public function __construct()
157
157
* Initializer for the curl resource.
158
158
*
159
159
* Is called by the __construct() of the class or when the curl request is reseted.
160
+ * @return self
160
161
*/
161
162
private function init ()
162
163
{
@@ -165,6 +166,7 @@ private function init()
165
166
$ this ->setOpt (CURLINFO_HEADER_OUT , true );
166
167
$ this ->setOpt (CURLOPT_HEADER , true );
167
168
$ this ->setOpt (CURLOPT_RETURNTRANSFER , true );
169
+ return $ this ;
168
170
}
169
171
170
172
// protected methods
@@ -253,6 +255,7 @@ public function _exec()
253
255
*
254
256
* @param string $url The url to make the get request for
255
257
* @param array $data Optional arguments who are part of the url
258
+ * @return self
256
259
*/
257
260
public function get ($ url , $ data = array ())
258
261
{
@@ -263,19 +266,22 @@ public function get($url, $data = array())
263
266
}
264
267
$ this ->setOpt (CURLOPT_HTTPGET , true );
265
268
$ this ->exec ();
269
+ return $ this ;
266
270
}
267
271
268
272
/**
269
273
* Make a post request with optional post data.
270
274
*
271
275
* @param string $url The url to make the get request
272
276
* @param array $data Post data to pass to the url
277
+ * @return self
273
278
*/
274
279
public function post ($ url , $ data = array ())
275
280
{
276
281
$ this ->setOpt (CURLOPT_URL , $ url );
277
282
$ this ->preparePayload ($ data );
278
283
$ this ->exec ();
284
+ return $ this ;
279
285
}
280
286
281
287
/**
@@ -286,6 +292,7 @@ public function post($url, $data = array())
286
292
* @param string $url The url to make the get request
287
293
* @param array $data Optional data to pass to the $url
288
294
* @param bool $payload Whether the data should be transmitted trough payload or as get parameters of the string
295
+ * @return self
289
296
*/
290
297
public function put ($ url , $ data = array (), $ payload = false )
291
298
{
@@ -298,6 +305,7 @@ public function put($url, $data = array(), $payload = false)
298
305
$ this ->setOpt (CURLOPT_URL , $ url );
299
306
$ this ->setOpt (CURLOPT_CUSTOMREQUEST , 'PUT ' );
300
307
$ this ->exec ();
308
+ return $ this ;
301
309
}
302
310
303
311
/**
@@ -308,6 +316,7 @@ public function put($url, $data = array(), $payload = false)
308
316
* @param string $url The url to make the get request
309
317
* @param array $data Optional data to pass to the $url
310
318
* @param bool $payload Whether the data should be transmitted trough payload or as get parameters of the string
319
+ * @return self
311
320
*/
312
321
public function patch ($ url , $ data = array (), $ payload = false )
313
322
{
@@ -320,6 +329,7 @@ public function patch($url, $data = array(), $payload = false)
320
329
$ this ->setOpt (CURLOPT_URL , $ url );
321
330
$ this ->setOpt (CURLOPT_CUSTOMREQUEST , 'PATCH ' );
322
331
$ this ->exec ();
332
+ return $ this ;
323
333
}
324
334
325
335
/**
@@ -328,6 +338,7 @@ public function patch($url, $data = array(), $payload = false)
328
338
* @param string $url The url to make the delete request
329
339
* @param array $data Optional data to pass to the $url
330
340
* @param bool $payload Whether the data should be transmitted trough payload or as get parameters of the string
341
+ * @return self
331
342
*/
332
343
public function delete ($ url , $ data = array (), $ payload = false )
333
344
{
@@ -339,6 +350,7 @@ public function delete($url, $data = array(), $payload = false)
339
350
$ this ->setOpt (CURLOPT_URL , $ url );
340
351
$ this ->setOpt (CURLOPT_CUSTOMREQUEST , 'DELETE ' );
341
352
$ this ->exec ();
353
+ return $ this ;
342
354
}
343
355
344
356
// setters
@@ -356,11 +368,13 @@ public function delete($url, $data = array(), $payload = false)
356
368
*
357
369
* @param string $username The username for the authentification
358
370
* @param string $password The password for the given username for the authentification
371
+ * @return self
359
372
*/
360
373
public function setBasicAuthentication ($ username , $ password )
361
374
{
362
375
$ this ->setHttpAuth (self ::AUTH_BASIC );
363
376
$ this ->setOpt (CURLOPT_USERPWD , $ username .': ' .$ password );
377
+ return $ this ;
364
378
}
365
379
366
380
/**
@@ -376,11 +390,13 @@ public function setBasicAuthentication($username, $password)
376
390
*
377
391
* @param string $key The header key
378
392
* @param string $value The value for the given header key
393
+ * @return self
379
394
*/
380
395
public function setHeader ($ key , $ value )
381
396
{
382
397
$ this ->_headers [$ key ] = $ key .': ' .$ value ;
383
398
$ this ->setOpt (CURLOPT_HTTPHEADER , array_values ($ this ->_headers ));
399
+ return $ this ;
384
400
}
385
401
386
402
/**
@@ -395,10 +411,12 @@ public function setHeader($key, $value)
395
411
* ```
396
412
*
397
413
* @param string $useragent The name of the user agent to set for the current request
414
+ * @return self
398
415
*/
399
416
public function setUserAgent ($ useragent )
400
417
{
401
418
$ this ->setOpt (CURLOPT_USERAGENT , $ useragent );
419
+ return $ this ;
402
420
}
403
421
404
422
/**
@@ -407,6 +425,7 @@ public function setUserAgent($useragent)
407
425
public function setReferrer ($ referrer )
408
426
{
409
427
$ this ->setReferer ($ referrer );
428
+ return $ this ;
410
429
}
411
430
412
431
/**
@@ -415,22 +434,26 @@ public function setReferrer($referrer)
415
434
* The $referer informations can help identify the requested client where the requested was made.
416
435
*
417
436
* @param string $referer An url to pass and will be set as referer header
437
+ * @return self
418
438
*/
419
439
public function setReferer ($ referer )
420
440
{
421
441
$ this ->setOpt (CURLOPT_REFERER , $ referer );
442
+ return $ this ;
422
443
}
423
444
424
445
/**
425
446
* Set contents of HTTP Cookie header.
426
447
*
427
448
* @param string $key The name of the cookie
428
449
* @param string $value The value for the provided cookie name
450
+ * @return self
429
451
*/
430
452
public function setCookie ($ key , $ value )
431
453
{
432
454
$ this ->_cookies [$ key ] = $ value ;
433
455
$ this ->setOpt (CURLOPT_COOKIE , http_build_query ($ this ->_cookies , '' , '; ' ));
456
+ return $ this ;
434
457
}
435
458
436
459
/**
@@ -454,16 +477,19 @@ public function setOpt($option, $value)
454
477
* @todo As to keep naming convention it should be renamed to `setVerbose()`
455
478
*
456
479
* @param string $on
480
+ * @return self
457
481
*/
458
482
public function verbose ($ on = true )
459
483
{
460
484
$ this ->setOpt (CURLOPT_VERBOSE , $ on );
485
+ return $ this ;
461
486
}
462
487
463
488
/**
464
489
* Reset all curl options.
465
490
*
466
491
* In order to make multiple requests with the same curl object all settings requires to be reset.
492
+ * @return self
467
493
*/
468
494
public function reset ()
469
495
{
@@ -483,16 +509,19 @@ public function reset()
483
509
$ this ->response_headers = null ;
484
510
$ this ->response = null ;
485
511
$ this ->init ();
512
+ return $ this ;
486
513
}
487
514
488
515
/**
489
516
* Closing the current open curl resource.
517
+ * @return self
490
518
*/
491
519
public function close ()
492
520
{
493
521
if (is_resource ($ this ->curl )) {
494
522
curl_close ($ this ->curl );
495
523
}
524
+ return $ this ;
496
525
}
497
526
498
527
/**
@@ -505,61 +534,55 @@ public function __destruct()
505
534
506
535
/**
507
536
* Was an 'info' header returned.
537
+ * @return bool
508
538
*/
509
539
public function isInfo ()
510
540
{
511
- if ($ this ->http_status_code >= 100 && $ this ->http_status_code < 200 ) {
512
- return true ;
513
- }
541
+ return $ this ->http_status_code >= 100 && $ this ->http_status_code < 200 ;
514
542
}
515
543
516
544
/**
517
545
* Was an 'OK' response returned.
546
+ * @return bool
518
547
*/
519
548
public function isSuccess ()
520
549
{
521
- if ($ this ->http_status_code >= 200 && $ this ->http_status_code < 300 ) {
522
- return true ;
523
- }
550
+ return $ this ->http_status_code >= 200 && $ this ->http_status_code < 300 ;
524
551
}
525
552
526
553
/**
527
554
* Was a 'redirect' returned.
555
+ * @return bool
528
556
*/
529
557
public function isRedirect ()
530
558
{
531
- if ($ this ->http_status_code >= 300 && $ this ->http_status_code < 400 ) {
532
- return true ;
533
- }
559
+ return $ this ->http_status_code >= 300 && $ this ->http_status_code < 400 ;
534
560
}
535
561
536
562
/**
537
563
* Was an 'error' returned (client error or server error).
564
+ * @return bool
538
565
*/
539
566
public function isError ()
540
567
{
541
- if ($ this ->http_status_code >= 400 && $ this ->http_status_code < 600 ) {
542
- return true ;
543
- }
568
+ return $ this ->http_status_code >= 400 && $ this ->http_status_code < 600 ;
544
569
}
545
570
546
571
/**
547
572
* Was a 'client error' returned.
573
+ * @return bool
548
574
*/
549
575
public function isClientError ()
550
576
{
551
- if ($ this ->http_status_code >= 400 && $ this ->http_status_code < 500 ) {
552
- return true ;
553
- }
577
+ return $ this ->http_status_code >= 400 && $ this ->http_status_code < 500 ;
554
578
}
555
579
556
580
/**
557
581
* Was a 'server error' returned.
582
+ * @return bool
558
583
*/
559
584
public function isServerError ()
560
585
{
561
- if ($ this ->http_status_code >= 500 && $ this ->http_status_code < 600 ) {
562
- return true ;
563
- }
586
+ return $ this ->http_status_code >= 500 && $ this ->http_status_code < 600 ;
564
587
}
565
588
}
0 commit comments