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
Installs: 100 829
Dependents: 4
Suggesters: 0
Security: 0
Stars: 11
Watchers: 3
Forks: 5
Open Issues: 0
Requires
- php: >=7.1.0
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^7.0
- squizlabs/php_codesniffer: ^2.0
README
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"