2017 © Pedro Peláez
 

library curlwrapper

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

image

phpcurl/curlwrapper

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  • Friday, March 2, 2018
  • by f3ath
  • Repository
  • 1 Watchers
  • 5 Stars
  • 28,106 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 13 Versions
  • 18 % Grown

The README.md

CurlWrapper for PHP

Total Downloads Latest Stable Version Travis Build SensioLabs Insight, (*1)

The simplest OOP-style wrapper for the standard php curl functions with no external dependencies. The main purpose is to make code that uses curl calls testable. We do it by injecting the Curl object as a dependency instead of calling curl functions directly., (*2)

Hard-coded dependencies. Not testable., (*3)

class MyApiClient {
    ...
    function call($url)
    {
        $ch = curl_init($url);
        curl_set_opt($ch, /*...*/)
        return curl_exec($ch);
    }
}

Testable code. Curl object is injected, so can be easily mocked in PHPUnit., (*4)

class MyApiClient {
    private $curl;
    function __construct(\PHPCurl\CurlWrapper\CurlInterface $curl)
    {
        $this->curl = $curl;
    }
    //...
    function call($url)
    {
        $this->curl->init($url);
        $this->curl->setOpt(/*...*/)
        return $this->curl->exec();
    }
}

Install

Via composer: $ composer require "phpcurl/curlwrapper", (*5)

Basic usage examples. Classic vs OOP style

Curl

Classic OOP
$h = curl_init($url) $curl = new Curl(); $curl->init($url)
curl_close($h) unset($curl)
$e = curl_errno($h) $e = $curl->errno()
$e = curl_error($h) $e = $curl->error()
$i = curl_getinfo($h, $opt) $i = $curl->getInfo($opt)
curl_setopt($h, $opt, $val) $curl->setOpt($opt, $val)
curl_setopt_array($h, $array) $curl->setOptArray($array)
curl_version($age) $curl->version($age)
curl_strerror($errornum) $curl->strerror($errornum)
$h2 = curl_copy_handle($h) $curl2 = clone($curl)
$result = curl_exec($h) $result = $curl->exec()
$res = curl_pause($h, $mask) $res = $curl->pause($mask)
$res = curl_escape($h, $str) $res = $curl->escape($str)
$res = curl_unescape($h, $str) $res = $curl->unescape($str)

CurlMulti

Classic OOP
curl_multi_init() $cm = new CurlMulti(); $cm->init()
curl_multi_close($h) unset($cm)
$i = curl_multi_add_handle($mh, $ch) $i = $cm->add($curl)
$i = curl_multi_remove_handle($mh, $ch) $i = $cm->remove($curl)
$i = curl_multi_exec($mh, $running) $i = $cm->exec($running)
$s = curl_multi_getcontent($ch) $s = $cm->getContent($curl)
$a = curl_multi_info_read($mh, $msgs) $a = $cm->infoRead($msgs)
$i = curl_multi_select($mh, $timeout) $i = $cm->select($timeout)
$r = curl_multi_setopt($h, $opt, $val) $r = $cm->setOpt($opt, $val)

CurlShare

Classic OOP
curl_share_init() $cs = new CurlShare(); $cs->init()
curl_share_close($h) unset($cs)
$r = curl_multi_setopt($h, $opt, $val) $r = $cs->setOpt($opt, $val)

The Versions

02/03 2018

dev-master

9999999-dev

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • ext-curl *
  • php >=7.0.0

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

02/03 2018

dev-f3ath-patch-1

dev-f3ath-patch-1

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=7.0.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

28/09 2017

v2.x-dev

2.9999999.9999999.9999999-dev

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.5.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

28/09 2017

v3.x-dev

3.9999999.9999999.9999999-dev

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.5.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

21/01 2017

2.1.0

2.1.0.0

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.5.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

21/01 2017

2.0.1

2.0.1.0

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.5.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

21/01 2017

2.0.0

2.0.0.0

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.5.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

03/02 2016

1.0.0

1.0.0.0

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi phpcurl testable curl_share

02/02 2016

0.1.2

0.1.2.0

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi testable curl_share

22/01 2016

0.1.1

0.1.1.0

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi testable curl_share

22/01 2016

0.1.0

0.1.0.0

The simplest OOP wrapper for curl, curl_multi, curl_share functions. Use CURL as a dependency, not hard-coded!

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

The Development Requires

by Alexey Karapetov

mock phpunit curl testing wrapper dependency injection oop curl_multi testable curl_share

20/02 2014

0.0.2

0.0.2.0

OOP wrapper for curl functions. Use CURL as a dependency, not hard-coded. Supports php up to 5.5.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

by Alexey Karapetov

curl testing dependency injection wrapper oop

18/02 2014

0.0.1

0.0.1.0

OOP wrapper for curl functions. Use CURL as a dependency, not hard-coded. Supports php up to 5.5.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

The Development Requires

  • f3ath/fock *

by Alexey Karapetov

curl testing dependency injection wrapper oop