juliangut / spiral
A PSR7 aware cURL client
Installs: 14 792
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 3
Open Issues: 1
Requires
- php: ^5.5|^7.0
- ext-curl: *
- lib-curl: *
- fig/http-message-util: ^1.0
- psr/http-message: ^1.0
- zendframework/zend-diactoros: ^1.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.0
- phpmd/phpmd: ~2.2
- phpunit/phpunit: ~4.5|^5.0
- sebastian/phpcpd: ~2.0
- squizlabs/php_codesniffer: ~2.3
README
PSR7 aware cURL client
PSR7 compatible cURL client.
Use PSR7 Request and Response objects to perform HTTP Requests with cURL.
Installation
Best way to install is using Composer:
composer require juliangut/spiral
Then require_once the autoload file:
require_once './vendor/autoload.php';
Usage
use Jgut\Spiral\Client; // Create Spiral cURL client $spiralClient = new Client; // Create \Psr\Http\Message\RequestInterface request and configure it $request = new PSR7RequestImplementation(); // Perform the request providing an empty \Psr\Http\Message\ResponseInterface response object to be populated $response = $spiralClient->request($request, new PSR7ResponseImplementation()); // Use response $headers = $response->getHeaders(); $content = (string) $response->getBody();
Transport
You can create an empty cURL transport object and set options on it later
$transport = new Curl; $spiralClient = new Client($transport);
Or you can create the transport object from sane defaults
$transport = Curl::createFromDefaults(); $spiralClient = new Client($transport);
If no transport object is provided to Jgut\Spiral\Client
constructor method one will be created by Jgut\Spiral\Transport\Curl::createFromDefaults
Options
Transport object accepts cURL options
use Jgut\Spiral\Transport\Curl; use Jgut\Spiral\Option\ConnectTimeout; // Create Spiral cURL client $transport = new Curl; // Set option explicitly $transport->setOption(new ConnectTimeout(10)); // Set by cURL constant $transport->setOption(CURLOPT_CONNECTTIMEOUT, 10); // Set using an alias $transport->setOption('connect_timeout', 10);
Reserved options
Some options are reserved and cannot be added to transport object using setOption
method. Some of them are set by extracting the relevant data from request oobject.
The following is a list of options automatically handled by the transport object
CURLOPT_NOBODY
CURLOPT_HTTPGET
CURLOPT_POST
CURLOPT_CUSTOMREQUEST
CURLOPT_URL
CURLOPT_POSTFIELDS
CURLOPT_HTTPHEADER
Available options
Review Jgut\Spiral\Option\OptionFactory for a full list of available aliases
Contributing
Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before
See file CONTRIBUTING.md
License
Release under BSD-3-Clause License.
See file LICENSE included with the source code for a copy of the license terms