Repository URL to install this package:
|
Version:
1.0.0 ▾
|
| scripts |
| src |
| tests |
| .gitignore |
| .travis.yml |
| README.md |
| phpunit.xml |
| composer.json |
This wrapper around php's curl functions. PHP 5.3 compatible for sad reasons.
Via composer
composer require crazyfactory/curl
Load a page
$responseBody = (new Curl)->get('http://www.example.org');
Pass in GET parameters as an array
$responseBody = (new Curl)->get($url, [ 'foo' => 'bar' ]);
Same for POST
$responseBody = (new Curl)->post($url, [ 'foo' => 'bar' ]);
For other methods, use call() directly.
call() accept an array of CURLOPT-constants and merges these with the defaults from getDefaultOptions(). post() and get() accept this array as 3rd parameter as well.
The last argument for all of these function is a reference to the returned curl-info for fancier things.
call() will throw CrazyFactory/Curl/Exception when any error happens. It will also throw an Exception on 400+ status codes.
try { (new Curl)->get('http://httpbin.org/status/404'); } catch (CrazyFactory/Curl/Exception $e) { echo "Whoops we had a {$e->getHttpCode()}!"; }