{"id":20498903,"url":"https://github.com/phpcurl/curlwrapper","last_synced_at":"2025-04-13T18:51:09.577Z","repository":{"id":57040267,"uuid":"50977209","full_name":"phpcurl/curlwrapper","owner":"phpcurl","description":"The simplest OOP cURL wrapper for PHP","archived":false,"fork":false,"pushed_at":"2020-01-31T07:29:44.000Z","size":50,"stargazers_count":11,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T09:40:24.650Z","etag":null,"topics":["curl","curl-multi","curlwrapper","dependency-injection","injectable","oop"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/phpcurl/curlwrapper","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpcurl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://www.paypal.me/f3ath"}},"created_at":"2016-02-03T05:46:41.000Z","updated_at":"2023-11-29T08:59:04.000Z","dependencies_parsed_at":"2022-08-23T23:30:39.879Z","dependency_job_id":null,"html_url":"https://github.com/phpcurl/curlwrapper","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpcurl%2Fcurlwrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpcurl%2Fcurlwrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpcurl%2Fcurlwrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpcurl%2Fcurlwrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpcurl","download_url":"https://codeload.github.com/phpcurl/curlwrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248765979,"owners_count":21158296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curl","curl-multi","curlwrapper","dependency-injection","injectable","oop"],"created_at":"2024-11-15T18:15:56.746Z","updated_at":"2025-04-13T18:51:09.553Z","avatar_url":"https://github.com/phpcurl.png","language":"PHP","readme":"# CurlWrapper for PHP\n[![Total Downloads](https://img.shields.io/packagist/dt/phpcurl/curlwrapper.svg)](https://packagist.org/packages/phpcurl/curlwrapper)\n[![Latest Stable Version](https://img.shields.io/packagist/v/phpcurl/curlwrapper.svg)](https://packagist.org/packages/phpcurl/curlwrapper)\n[![Travis Build](https://travis-ci.org/phpcurl/curlwrapper.svg?branch=master)](https://travis-ci.org/phpcurl/curlwrapper)\n[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/f6dd716c-7729-46f2-903f-12a53e427841.svg)](https://insight.sensiolabs.com/projects/f6dd716c-7729-46f2-903f-12a53e427841)\n\nThe simplest OOP-style wrapper for the standard php curl functions with no external dependencies.\nThe main purpose is to make code that uses curl calls testable. \nWe do it by injecting the Curl object as a dependency instead of calling curl functions directly.\n\n\nHard-coded dependencies. Not testable.\n```php\nclass MyApiClient {\n    ...\n    function call($url)\n    {\n        $ch = curl_init($url);\n        curl_set_opt($ch, /*...*/)\n        return curl_exec($ch);\n    }\n}\n```\n\n\nTestable code. Curl object is injected, so can be easily mocked in PHPUnit.\n```php\nclass MyApiClient {\n    private $curl;\n    function __construct(\\PHPCurl\\CurlWrapper\\CurlInterface $curl)\n    {\n        $this-\u003ecurl = $curl;\n    }\n    //...\n    function call($url)\n    {\n        $this-\u003ecurl-\u003einit($url);\n        $this-\u003ecurl-\u003esetOpt(/*...*/)\n        return $this-\u003ecurl-\u003eexec();\n    }\n}\n```\n\n## Install\nVia [composer](https://getcomposer.org):\n`$ composer require \"phpcurl/curlwrapper\"`\n\n\n## Basic usage examples. Classic vs OOP style\n\n### Curl\n\n| Classic                          | OOP |\n| ---                              | --- |\n| `$h = curl_init($url)`           | `$curl = new Curl(); $curl-\u003einit($url)` |\n| `curl_close($h)`                 | `unset($curl)` |\n| `$e = curl_errno($h)`            | `$e = $curl-\u003eerrno()` |\n| `$e = curl_error($h)`            | `$e = $curl-\u003eerror()` |\n| `$i = curl_getinfo($h, $opt)`    | `$i = $curl-\u003egetInfo($opt)` |\n| `curl_setopt($h, $opt, $val)`    | `$curl-\u003esetOpt($opt, $val)` |\n| `curl_setopt_array($h, $array)`  | `$curl-\u003esetOptArray($array)` |\n| `curl_version($age)`             | `$curl-\u003eversion($age)` |\n| `curl_strerror($errornum)`       | `$curl-\u003estrerror($errornum)` |\n| `$h2 = curl_copy_handle($h)`     | `$curl2 = clone($curl)` |\n| `$result = curl_exec($h)`        | `$result = $curl-\u003eexec()` |\n| `$res = curl_pause($h, $mask)`   | `$res = $curl-\u003epause($mask)` |\n| `$res = curl_escape($h, $str)`   | `$res = $curl-\u003eescape($str)` |\n| `$res = curl_unescape($h, $str)` | `$res = $curl-\u003eunescape($str)` |\n\n### CurlMulti\n\n| Classic                                    | OOP |\n| ---                                        | --- |\n| `curl_multi_init()`                        |   `$cm = new CurlMulti(); $cm-\u003einit()` |\n| `curl_multi_close($h)`                     |   `unset($cm)` |\n| `$i = curl_multi_add_handle($mh, $ch)`     |   `$i = $cm-\u003eadd($curl)` |\n| `$i = curl_multi_remove_handle($mh, $ch)`  |   `$i = $cm-\u003eremove($curl)` |\n| `$i = curl_multi_exec($mh, $running)`      |   `$i = $cm-\u003eexec($running)` |\n| `$s = curl_multi_getcontent($ch)`          |   `$s = $cm-\u003egetContent($curl)` |\n| `$a = curl_multi_info_read($mh, $msgs)`    |   `$a = $cm-\u003einfoRead($msgs)` |\n| `$i = curl_multi_select($mh, $timeout)`    |   `$i = $cm-\u003eselect($timeout)` |\n| `$r = curl_multi_setopt($h, $opt, $val)`   |   `$r = $cm-\u003esetOpt($opt, $val)` |\n\n### CurlShare\n\n| Classic                                  | OOP |\n| ---                                      | --- |\n| `curl_share_init()`                      |   `$cs = new CurlShare(); $cs-\u003einit()` |\n| `curl_share_close($h)`                   |   `unset($cs)` |\n| `$r = curl_multi_setopt($h, $opt, $val)` |   `$r = $cs-\u003esetOpt($opt, $val)` |\n","funding_links":["https://www.paypal.me/f3ath"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpcurl%2Fcurlwrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpcurl%2Fcurlwrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpcurl%2Fcurlwrapper/lists"}