kukymbr / curl-wrapper
cURL functions wrapper
v0.9.2
2019-11-20 09:02 UTC
Requires
- php: >=7.0.0
- ext-curl: >=7.0
This package is not auto-updated.
Last update: 2024-10-03 08:17:52 UTC
README
cURL php functions OOP wrapper.
Requirements
Requires PHP 7.0+.
Installation
The supported way of installing Curl is via Composer.
$ composer require kukymbr/curl-wrapper
Usage
<?php
use Kukymbr\CurlWrapper\Curl;
// Create Curl instance
$curl = new Curl();
// Set handler options
$curl->setOptArray(
[
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FAILONERROR => true,
// ... any others CURLOPT_* options
]
);
// Request the "https://example.com?foo-bar" URL
$response = $curl->exec('https://example.com', ['foo' => 'bar']);
// Get the response code
$responseCode = $curl->getResponseCode();
All of curl_* functions are available in lowerCamelCase,
for example $curl->fileCreate()
will cause a call of curl_file_create
function.
Using with default values
If you need set your own default curl options,
extend Curl and override the _getDefaultOptions
method:
<?php
class MyCurl extends \Kukymbr\CurlWrapper\Curl
{
/**
* Get default cURL options.
*
* @return array
*/
protected function _getDefaultOptions() : array
{
return [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FAILONERROR => true,
];
}
}
License
The MIT License (MIT). Please see License File for more information.