phpcurl/curlwrapper

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

Fund package maintenance!
www.paypal.me/f3ath

3.0.0 2018-11-02 00:34 UTC

This package is auto-updated.

Last update: 2024-10-29 03:48:23 UTC


README

Total Downloads Latest Stable Version Travis Build SensioLabs Insight

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.

Hard-coded dependencies. Not testable.

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.

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"

Basic usage examples. Classic vs OOP style

Curl

CurlMulti

CurlShare