2017 © Pedro Peláez
 

library spiral

A PSR7 aware cURL client

image

juliangut/spiral

A PSR7 aware cURL client

  • Saturday, June 3, 2017
  • by juliangut
  • Repository
  • 2 Watchers
  • 3 Stars
  • 1,357 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 6 Versions
  • 27 % Grown

The README.md

PHP version Latest Version License, (*1)

Build Status Style Check Code Quality Code Coverage, (*2)

Total Downloads Monthly Downloads, (*3)

PSR7 aware cURL client

PSR7 compatible cURL client., (*4)

Use PSR7 Request and Response objects to perform HTTP Requests with cURL., (*5)

Installation

Best way to install is using Composer:, (*6)

composer require juliangut/spiral

Then require_once the autoload file:, (*7)

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, (*8)

$transport = new Curl;

$spiralClient = new Client($transport);

Or you can create the transport object from sane defaults, (*9)

$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, (*10)

Options

Transport object accepts cURL options, (*11)

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., (*12)

The following is a list of options automatically handled by the transport object, (*13)

  • CURLOPT_NOBODY
  • CURLOPT_HTTPGET
  • CURLOPT_POST
  • CURLOPT_CUSTOMREQUEST
  • CURLOPT_URL
  • CURLOPT_POSTFIELDS
  • CURLOPT_HTTPHEADER

Available options

Option class Alias cURL constant Value type
AutoReferer auto_referer CURLOPT_AUTOREFERER bool
ConnectTimeout connect_timeout CURLOPT_CONNECTTIMEOUT int
Cookie cookie CURLOPT_COOKIE string
CookieFile cookie_file CURLOPT_COOKIEFILE string
CookieJar cookie_jar CURLOPT_COOKIEJAR string
Crlf crlf CURLOPT_CRLF bool
Encoding encoding CURLOPT_ENCODING string
FileTime file_time CURLOPT_FILETIME bool
FollowLocation follow_location CURLOPT_FOLLOWLOCATION bool
Header header CURLOPT_HEADER bool
HeaderOut header_out CURLINFO_HEADER_OUT bool
HttpAuth http_auth CURLOPT_HTTPAUTH bool
HttpVersion http_version CURLOPT_HTTP_VERSION float (1.0 or 1.1)
MaxRedirs max_redirs CURLOPT_MAXREDIRS int
Port port CURLOPT_PORT int
Referer referer CURLOPT_REFERER string
ReturnTransfer return_transfer CURLOPT_RETURNTRANSFER bool
SslVerifyPeer ssl_verify_peer CURLOPT_SSL_VERIFYPEER bool
SslVersion ssl_version CURLOPT_SSLVERSION int
Timeout timeout CURLOPT_TIMEOUT int
UnrestrictedAuth unrestricted_auth CURLOPT_UNRESTRICTED_AUTH bool
UserAgent user_agent CURLOPT_USERAGENT string
UserPwd user_password CURLOPT_USERPWD string (user:password)
Verbose verbose CURLOPT_VERBOSE bool

Review Jgut\Spiral\Option\OptionFactory for a full list of available aliases, (*14)

Contributing

Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before, (*15)

See file CONTRIBUTING.md, (*16)

License

Release under BSD-3-Clause License.

See file LICENSE included with the source code for a copy of the license terms, (*17)

The Versions

30/10 2015

0.1.1

0.1.1.0 http://github.com/juliangut/spiral

Spiral: PSR7 aware cURL client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

curl psr7 request response

29/10 2015

0.1

0.1.0.0 http://github.com/juliangut/spiral

Spiral: PSR7 aware cURL client

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

curl psr7 request response