2017 © Pedro Peláez
 

library curl

Simple OOP cURL wrapper.

image

anlutro/curl

Simple OOP cURL wrapper.

  • Tuesday, April 10, 2018
  • by anlutro
  • Repository
  • 15 Watchers
  • 197 Stars
  • 305,211 Installations
  • PHP
  • 43 Dependents
  • 0 Suggesters
  • 50 Forks
  • 6 Open issues
  • 27 Versions
  • 6 % Grown

The README.md

php-curl

Build Status Latest Stable Version Latest Unstable Version License, (*1)

The smallest possible OOP wrapper for PHP's curl capabilities., (*2)

Note that this is not meant as a high-level abstraction. You should still know how "pure PHP" curl works, you need to know the curl options to set, and you need to know some HTTP basics., (*3)

If you're looking for a more user-friendly abstraction, check out Guzzle., (*4)

Installation

$ composer require anlutro/curl

Usage

$curl = new anlutro\cURL\cURL;

$response = $curl->get('http://www.google.com');

// easily build an url with a query string
$url = $curl->buildUrl('http://www.google.com', ['s' => 'curl']);
$response = $curl->get($url);

// the post, put and patch methods takes an array of POST data
$response = $curl->post($url, ['api_key' => 'my_key', 'post' => 'data']);

// add "json" to the start of the method to convert the data to a JSON string
// and send the header "Content-Type: application/json"
$response = $curl->jsonPost($url, ['post' => 'data']);

// if you don't want any conversion to be done to the provided data, for example
// if you want to post an XML string, add "raw" to the start of the method
$response = $curl->rawPost($url, '<?xml version...');

// raw request are also the easiest way to upload files
$file = curl_file_create('/path/to/file');
$response = $curl->rawPost($url, ['file' => $file]);

// a response object is returned
var_dump($response->statusCode); // response status code integer (for example, 200)
var_dump($response->statusText); // full response status (for example, '200 OK')
echo $response->body;
var_dump($response->headers); // array of headers
var_dump($response->info); // array of curl info

If you need to send headers or set cURL options you can manipulate a request object directly. send() finalizes the request and returns the result., (*5)

// newRequest, newJsonRequest and newRawRequest returns a Request object
$request = $curl->newRequest('post', $url, ['foo' => 'bar'])
    ->setHeader('Accept-Charset', 'utf-8')
    ->setHeader('Accept-Language', 'en-US')
    ->setOption(CURLOPT_CAINFO, '/path/to/cert')
    ->setOption(CURLOPT_FOLLOWLOCATION, true);
$response = $request->send();

You can also use setHeaders(array $headers) and setOptions(array $options) to replace all the existing options., (*6)

Note that some curl options are reset when you call send(). Look at the source code of the method cURL::prepareMethod for a full overview of which options are overwritten., (*7)

HTTP basic authentication:, (*8)

$request = $curl->newRequest('post', $url, ['foo' => 'bar'])
    ->setUser($username)->setPass($password);

Laravel

The package comes with a facade you can use if you prefer the static method calls over dependency injection., (*9)

You do not need to add a service provider., (*10)

Optionally, add 'cURL' => 'anlutro\cURL\Laravel\cURL' to the array of aliases in config/app.php., (*11)

Replace $curl-> with cURL:: in the examples above., (*12)

Contact

Open an issue on GitHub if you have any problems or suggestions., (*13)

License

The contents of this repository is released under the MIT license., (*14)

The Versions

10/04 2018

dev-master

9999999-dev

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

07/06 2017

1.4.4

1.4.4.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

05/05 2017

dev-develop

dev-develop

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

05/05 2017

1.4.3

1.4.3.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

23/03 2016

1.4.2

1.4.2.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

10/12 2015

1.4.1

1.4.1.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

24/10 2015

1.4.0

1.4.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

30/07 2015

1.3.3

1.3.3.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

30/07 2015

1.3.2

1.3.2.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

27/07 2015

1.3.1

1.3.1.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

20/07 2015

1.3.0

1.3.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

13/07 2015

1.2.0

1.2.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

13/07 2015

1.1.1

1.1.1.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

07/07 2015

1.1.0

1.1.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

03/07 2015

1.0.0

1.0.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

12/11 2014

0.6.2

0.6.2.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

28/07 2014

0.6.1

0.6.1.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

03/04 2014

0.6.0

0.6.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

23/01 2014

0.5.0

0.5.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

12/01 2014

0.4.3

0.4.3.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

12/01 2014

0.4.2

0.4.2.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

11/01 2014

0.4.1

0.4.1.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

11/01 2014

0.4.0

0.4.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Andreas Lutro

30/12 2013

0.3.0

0.3.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Andreas Lutro

13/12 2013

0.2.0

0.2.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Andreas Lutro

09/11 2013

0.1.1

0.1.1.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Andreas Lutro

01/11 2013

0.1.0

0.1.0.0

Simple OOP cURL wrapper.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Andreas Lutro